自定义的界面底部向上弹出的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);
  }

}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lrpshuai/article/details/52382394
文章标签: 底部向上弹出popw
个人分类: 分享
上一篇Android中IDE、ADT、SDK、JDK、NDK的解释
下一篇在ScrollView中加入listview后的处理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭