【转】PopupWindow用法
来源:互联网 发布:ubuntu搜狗输入法乱码 编辑:程序博客网 时间:2024/05/17 08:02
http://www.cnblogs.com/noTice520/archive/2011/08/16/2140356.html
http://www.2cto.com/kf/201108/100378.html
http://www.cnblogs.com/noTice520/archive/2011/02/15/1955541.html
使用PopupWindow可实现弹出窗口效果,,其实和AlertDialog一样,也是一种对话框,两者也经常混用,但是也各有特点。下面就看看使用方法。
首先初始化一个PopupWindow,指定窗口大小参数。
PopupWindow mPop =newPopupWindow(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(newColorDrawable(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, intyoff)
3、进出场动画
pop.setAnimationStyle(R.style.PopupAnimation);
4、点击PopupWindow区域外部,PopupWindow消失
this.window.setTouchInterceptor(new
@Override
public
if(event.getAction()
BetterPopupWindow.this.window.dismiss();
return
}
return
}
});
- 【转】PopupWindow用法
- PopupWindow用法
- PopupWindow 用法
- PopupWindow用法
- popupwindow用法
- PopupWindow用法
- PopupWindow用法
- PopupWindow用法
- PopupWindow用法
- PopupWindow用法
- PopupWindow用法
- PopupWindow用法
- Android popupWindow 用法
- android PopupWindow的用法
- android—PopupWindow用法
- popupWindow简单用法实例
- popupwindow的用法
- PopupWindow的用法
- 黑马程序员-----初识OC(一)
- [JS][easyui]jQuery EasyUI Datagrid性能优化专题
- poj2245lotto
- uva 10537 - The Toll! Revisited (逆向思维最短路)
- Android学习之路 很实用!!!
- 【转】PopupWindow用法
- Busybox下tftp命令使用详解
- [JS][easyui]jQuery EasyUI Datagrid VirtualScrollView视图简单分析
- 计算机世界是一个庞大的库
- css box-shadow效果演示
- 朴素搜索dfs, 简单的剪枝搜索
- Java深入 - Filter过滤器
- Scrapy源码分析-所有爬虫的基类-Spider(二)
- JVM 堆内存设置原理技术详解及案例分析