popupwindow提示框

public void PopupWindow(View parent){
        View contentView = View.inflate(context,R.layout.popup_item, null);
        //先把之前的銷燬
        dismissPopupWindow();

        //-2表示包裹內容
        popupwindow = new PopupWindow(contentView, -2, -2);
        // 動畫播放有一個前提條件: 窗體必須要有背景資源。 如果窗體沒有背景,動畫就播放不出來。
        popupwindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        int[] location = new int[2];
        view.getLocationInWindow(location);
        popupwindow.showAtLocation(parent, Gravity.LEFT + Gravity.TOP, 60, location[1]);

        ScaleAnimation sa = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 0.5f);
        sa.setDuration(200);
        AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
        aa.setDuration(200);
        AnimationSet set = new AnimationSet(false);
        set.addAnimation(aa);
        set.addAnimation(sa);
        contentView.startAnimation(set);
    }
private void dismissPopupWindow() {
       if (popupwindow != null && popupwindow.isShowing()) {
            popupwindow.dismiss();
            popupwindow = null;
       }
  }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章