Android PopWindow的简单应用

来源:互联网 发布:603881数据港股吧 编辑:程序博客网 时间:2024/04/29 05:25

1、由按钮触发的,显示在屏幕某一小部分的popWindow

View popupView = LayoutInflater.from(v.getContext()).inflate(R.layout.popchild, null);//设置popWindow的布局  window =new PopupWindow(  popupView,//布局  LayoutParams.MATCH_PARENT,//横向满屏  LayoutParams.WRAP_CONTENT//纵向包裹  );       window.setFocusable(true);      window.setOutsideTouchable(true);      window.setBackgroundDrawable(new BitmapDrawable());                      window.showAsDropDown(l3);//显示出来,里面的参数是触发的view,用于规定其大体的位置

2、从侧面划出的popWindow,有点像抽屉效果,但比抽屉效果好

  window =new PopupWindow(  popupView,//布局  700,//宽度  LayoutParams.MATCH_PARENT,//高度  true //可成为焦点  );       window.setFocusable(true);      window.setOutsideTouchable(true);      window.setBackgroundDrawable(new BitmapDrawable());            listview1=(ListView) popupView.findViewById(R.id.listView1);//可以从popView里                 try {if(resultList!=null&&resultList.size()>0)  window.showAtLocation(  listview1, //唤醒view,是popView里面的view  Gravity.RIGHT,//靠右边出来  0,//x偏移  0//y偏移  );

3、仿弹出对话框的效果

 View popupView = LayoutInflater.from(v.getContext()).inflate(R.layout.comment, null);    window =new PopupWindow(  popupView,//布局  LayoutParams.MATCH_PARENT,//横向满屏,但是注意,如果这里不满屏,布局里面写满屏,出来以后不是满屏,所以必须在这里写满屏  LayoutParams.WRAP_CONTENT,//纵向包裹  true   );       window.setFocusable(true);      window.setOutsideTouchable(true);      window.setBackgroundDrawable(new BitmapDrawable());  window.showAtLocation(  v, //大概位置  Gravity.TOP,//居顶  0,//横向偏移  360//纵向的偏移,偏移到大约中间位置即可  );



0 0