popupwindows
来源:互联网 发布:黑马校对软件下载 编辑:程序博客网 时间:2024/04/29 21:27
首先初始化一个PopupWindow,指定窗口大小参数。
PopupWindow mPop = new PopupWindow(getLayoutInflater().inflate(R.layout.window, null),
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
也可以分开写:
LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
//自定义布局
ViewGroup menuView = (ViewGroup) mLayoutInflater.inflate(
PopupWindow mPop = new PopupWindow(menuView, LayoutParams.WRAP_CONTENT,
当然也可以手动设置PopupWindow大小。
mPop.setContentView(menuView );//设置包含视图
mPop.setWidth(int )
mPop.setHeight(int )//设置弹出框大小
设置进场动画:
mPop.setAnimationStyle(R.style.AnimationPreview);//设置动画样式
当有mPop.setFocusable(false);的时候,说明PopuWindow不能获得焦点,即使设置设置了背景不为空也不能点击外面消失,只能由dismiss()消失,但是外面的View的事件还是可以触发,back键也可以顺利dismiss掉。当设置为popuWindow.setFocusable(true);的时候,加上下面两行设置背景代码,点击外面和Back键才会消失。
mPop.setFocusable(true);需要顺利让PopUpWindow
mPop.setBackgroundDrawable(new ColorDrawable(0));
mPop.showAsDropDown(anchor, 0, 0);//设置显示PopupWindow的位置位于View的左下方,x,y表示坐标偏移量
mPop.showAtLocation(findViewById(R.id.parent),
注:window.xml为布局文件
总结:
1、为PopupWindow的view布局,通过LayoutInflator获取布局的view.如:
LayoutInflater
this.anchor.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View
2、显示位置,可以有很多方式设置显示方式
pop.showAtLocation(findViewById(R.id.ll2),
或者
pop.showAsDropDown(View anchor, int xoff, int yoff)
3、进出场动画
pop.setAnimationStyle(R.style.PopupAnimation);
4、点击PopupWindow区域外部,PopupWindow消失
this.window.setTouchInterceptor(new
@Override
public
if(event.getAction()
BetterPopupWindow.this.window.dismiss();
return
}
return
}
});
- popupwindows
- popupwindows
- Android PopupWindows
- Android PopupWindows
- popupwindows用例
- PopupWindows弹窗
- Android中的PopupWindows用法
- android---(PopupWindows、Notification)
- popupWindows的位置设置
- 安卓中PopupWindows的使用
- Android中的PopupWindows详解
- 使PopupWindows的EditText获得焦点
- PopupWindows全屏及半透明背景代码
- PopupWindows(提示框)代码详解
- PopupWindows 在指定控件上下左右显示
- Android 弹出PopupWindows背景变透明
- PopupWindows与外部输入框焦点问题
- 项目中那些事|初探 弹出框 PopupWindows
- NYOJ 628 小媛在努力
- RHEL5 配置 xamager
- python中的self
- 算法竞赛入门经典 习题3-6十进制转n进制
- Cohen-Sutherland算法
- popupwindows
- UVA138- Street Numbers
- Bullet physics物理引擎学习笔记
- 算法竞赛入门经典 习题3-5矩阵旋转
- Sutherland-Hodgeman多边形裁剪(转载)
- 论文页眉页脚设置
- ios app开发教程告诉你开发不可缺少的2个工具
- Using Lists as Queues in Python----在Python中把链表当作队列使用
- list排序加去重功能