自定義的界面底部向上彈出的PopupWindow

public class BottomPopWin extends PopupWindow {

  private final TextView tvTotaDoneNums;
  private final GridView gvSelectNum;
  private View view;

  public BottomPopWin(Activity cx) {
    DisplayMetrics dm = new DisplayMetrics();
    cx.getWindowManager().getDefaultDisplay().getMetrics(dm);
    Rect rect = new Rect();
    cx.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    int top = rect.top;
    View v = cx.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    int top2 = v.getTop();
    this.view = LayoutInflater.from(cx).inflate(R.layout.bootomdialog, null);
    tvTotaDoneNums = (TextView) view.findViewById(R.id.tv_dialog_btm_num_done);
    gvSelectNum = (GridView) view.findViewById(R.id.gv_nums);
    this.setOutsideTouchable(true);
    this.view.setOnTouchListener(new View.OnTouchListener() {

      public boolean onTouch(View v, MotionEvent event) {
        int height = view.findViewById(R.id.ll_dialog_btm_content).getTop();
        int y = (int) event.getY();
        if (event.getAction() == MotionEvent.ACTION_UP) {
          if (y < height) {
            dismiss();
          }
        }
        return true;
      }
    });
    this.setContentView(this.view);
    this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
    this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
    this.setFocusable(true);
    ColorDrawable dw = new ColorDrawable(0x50000000);
    this.setBackgroundDrawable(dw);
    this.setAnimationStyle(R.style.pop_anim);
  }

  public GridView getGridView(){
    return gvSelectNum;
  }

  public void setTotalDoneNum(String num){
    if (tvTotaDoneNums!=null){}
    tvTotaDoneNums.setText(num);
  }

}

發佈了41 篇原創文章 · 獲贊 8 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章