PopWindows详解
来源:互联网 发布:resellerclub域名 编辑:程序博客网 时间:2024/05/20 20:04
PopWindows详解
1、pop布局(activity_pop.xml):
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Buttonandroid:id="@+id/button_one"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="button" /><Buttonandroid="@+id/button_two"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="button" /></LinearLayout>
2、初始化PopupWindow:
LayoutInflater inflater = LayoutInflater.from(getApplication());// 获取当面界面的主布局View rootView = MainActivity.this.findViewById(R.id.ll_main);View popView = inflater.inflate(R.layout.activity_pop, null, false);pop = new PopupWindow(popView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);// 需要设置一下此参数,点击外边可消失// 如果不设置PopupWindow的背景,有些版本就会出现一个问题:无论是点击外部区域还是Back键都无法dismiss弹框pop.setBackgroundDrawable(new BitmapDrawable());// 设置此参数获得焦点,否则无法点击pop.setFocusable(true);// 设置点击窗口外边窗口消失pop.setOutsideTouchable(true);
3、弹出PopupWindow:
//在当前界面正下方显示pop.showAtLocation(rootView, Gravity.BOTTOM, 0, 0);// 显示在相对于view的左下方(这个左下方是在屏幕的左下方)pop.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, 0, 0);// 用来保存按钮view的坐标,location[0]是X轴,location[1]是Y轴int[] location = new int[2];Log.d("Taonce", "location:" + location.toString());view.getLocationOnScreen(location);// 在按钮view的左边pop.showAtLocation(view, Gravity.NO_GRAVITY, location[0] - view.getWidth(), location[1]);// 左上方pop.showAtLocation(view, Gravity.NO_GRAVITY, location[0] - view.getWidth(), location[1] - view.getHeight());// 左下方pop.showAtLocation(view, Gravity.NO_GRAVITY, location[0] - view.getWidth(), location[1] + view.getHeight());
这里我只列举了几种,其他的可以自己试验下。
注意:上面的view是Button是onClick(View view)中的view。
4、pop的点击事件:
Button button_one = popView.findViewById(R.id.button_one);button_one.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(getApplication(),"on click one",Toast.LENGTH_SHORT);// 记得dismiss掉pop.dismiss();}});
阅读全文
1 0
- PopWindows详解
- popwindows
- popwindows
- popWindows
- 继承PopWindows
- Android popwindows
- android popwindows简单示例
- popwindows小研究
- PopWindows背景半透明设置
- PopWindows 底部显示与隐藏
- Android开发之PopWindows弹出式菜单
- android 动画效果 activity 和popwindows
- PopWindows放在某个控件的下面
- PopWindows 下拉列表框 spinner 锚点
- android2.3系统popwindows构造函数会挂
- 使用popwindows实现Actionbar右上角的小菜单
- PopWindows如何在屏幕的中间显示的问题.
- popWindows设置背景色及相应的布局
- 从数据库取Blob数据
- MySql之视图
- SpringCloud学习_3(注册中心的高可用)
- Django学习(九)(QuerySet API)
- 浅述经典的4种卷积网络之(1)AlexNet
- PopWindows详解
- 蓝牙核心技术概述(三): 蓝牙协议规范(射频、基带链路控制、链路管理)
- Excel 数字按长度补0,并转换为文本
- 我的Tensorflow学习之路
- RocketMQ的坑(一)--搭好环境跑起来
- 39.线程同步
- 注解(Annotation)自定义注解入门
- Android设计模式——单例的七种写法
- wangEditor3使用AJAX异步上传图片