关闭

自定义的界面底部向上弹出的PopupWindow

标签: 底部向上弹出popw
86人阅读 评论(0) 收藏 举报
分类:

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);
  }

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5495次
    • 积分:402
    • 等级:
    • 排名:千里之外
    • 原创:34篇
    • 转载:3篇
    • 译文:0篇
    • 评论:8条
    文章分类
    最新评论