博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PopupWindow介绍
阅读量:6905 次
发布时间:2019-06-27

本文共 1641 字,大约阅读时间需要 5 分钟。

  • Android的对话框有两种:PopupWindow AlertDialog.他们的不同点在于AlertDialog的位置固定,而PopupWindow的位置可以随意

    PopupWindow的位置按照有无偏移,可以分为偏移和无偏移两种 按照参照物的不同,可以分为相对于某个控件(Anchor锚)和相对于父控件

    具体如下:

mPopupWindow.showAsDropDown(View anchor);  相对于某个控件的位置(正下方),无偏移    mPopupWindow.showAsDropDown(View anchor,int oxoff,int yoff);  相对于某个控件的位置,有偏移    mPopupWindow.showAtLocation(View parent,int gravity,int x,int y);  相对于父控件的位置,例如正中央Gravity.CENTER,下方Gravity.BOTTOMdeng )复制代码

//创建一个PopupWindow

//参数1、contentView指定PopupWindow的内容	//参数2、width	//参数3、height复制代码
PopupWindow mPopupWindow = new PopupWindow(textView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);复制代码
//设置PopupWindow的相关属性                 //设置背景                            mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.mipmap.ic_launcher));                            mPopupWindow.getBackground().setAlpha(100); //设置透明度                            //mPopupWindow.setAnimationStyle(); //设置动画效果                            复制代码
//设置点击窗口外边窗口消失           mPopupWindow.setOutsideTouchable(true);           mPopupWindow.setFocusable(true);           mPopupWindow.setTouchable(true);复制代码
//防止虚拟软键盘呗弹出菜单遮住        mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);        //显示弹窗        //相对于某个控件的位置(正下方)  无偏移        mPopupWindow.showAsDropDown(v);        //相对于某个控件的位置(正左下方)  有偏移        mPopupWindow.showAsDropDown(v,50,50);  //x.y方向各偏移50        //相对于父控件的位置  无偏移        mPopupWindow.showAtLocation(v, Gravity.CENTER,0,0);        //相对于父控件的位置,有偏移        mPopupWindow.showAtLocation(v,Gravity.BOTTOM,0,50);                //关闭弹窗        mPopupWindow.dismiss();复制代码

转载地址:http://qwmdl.baihongyu.com/

你可能感兴趣的文章
Item 46: Use Built-in Algorithms and Data Structures
查看>>
UIkit框架(14)自定义标签控制器
查看>>
文件的读写
查看>>
夭折的TMG,微软停止开发TMG 相关产品
查看>>
坑- observeOn(AndroidSchedulers.mainThread())
查看>>
我的友情链接
查看>>
Vert.x 单元测试 译<六>
查看>>
Pyhton扫描端口脚本
查看>>
redis队列(set)
查看>>
ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案
查看>>
我的友情链接
查看>>
解决eclipse创建项目,jdk版本太旧问题
查看>>
架构师进阶:Linux进程间如何共享内存?
查看>>
笨方法学Python,Lesson 26
查看>>
笨方法学python Lesson 45
查看>>
Java HashMap的实现原理
查看>>
服务器的发送数据
查看>>
kvm install 报错could not open disk imageXXX: Permission denied
查看>>
lduan office 365 自定义域的添加和配置二
查看>>
在Wordpress侧栏中使用下拉菜单显示分类
查看>>