Android PopupWindow的使用
2015-08-03 15:04
591 查看
PopupWindow是Android中实现弹窗效果的一个类:
1.实例化一个PopupWindowView contentView = getLayoutInflater().inflate(R.layout.popwindow, null);
PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
2.PopupWindow的显示方式
popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);第一个参数是PopupWindow显示在那个view上,第二个参数是PopupWindow的显示位置,第三四个参数是PopupWindow的偏移量
另外一种显示方式是showAsDropDown(View anchor) 或showAsDropDown(View anchor, int xoff, int yoff)
3.showAtLocation和showAsDropDown的区别
PopupWindow是设置相对某一个父view的显示方式,而showAsDropDown是设置相对于控件的向下弹出的显示方式
4.PopupWindow获取焦点
popupWindow.setFocusable(true);
5.点击PopupWindow之外的区域关闭PopupWindow
popupWindow.setBackgroundDrawable(new BitmapDrawable());
6.PopupWindow显示和消失动画
popupWindow.setAnimationStyle(R.style.animation);
7.关闭PopupWindow
popupWindow.dismiss();
1.实例化一个PopupWindowView contentView = getLayoutInflater().inflate(R.layout.popwindow, null);
PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
2.PopupWindow的显示方式
popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);第一个参数是PopupWindow显示在那个view上,第二个参数是PopupWindow的显示位置,第三四个参数是PopupWindow的偏移量
另外一种显示方式是showAsDropDown(View anchor) 或showAsDropDown(View anchor, int xoff, int yoff)
3.showAtLocation和showAsDropDown的区别
PopupWindow是设置相对某一个父view的显示方式,而showAsDropDown是设置相对于控件的向下弹出的显示方式
4.PopupWindow获取焦点
popupWindow.setFocusable(true);
5.点击PopupWindow之外的区域关闭PopupWindow
popupWindow.setBackgroundDrawable(new BitmapDrawable());
6.PopupWindow显示和消失动画
popupWindow.setAnimationStyle(R.style.animation);
7.关闭PopupWindow
popupWindow.dismiss();
相关文章推荐
- Android egl和opengl
- Android中保存数据到sd卡
- Android:OTG+MediaScanner
- Android屏幕适配,百分比布局
- Android安卓开发环境搭建详细教程
- Android进阶之视频录制播放常见问题
- Android Activity 和 ViewGroup中事件触发和传递机制
- Android Studio常用小技巧
- Android Fragment 真正的完全解析(上)
- Android studio使用
- Android接口解析方法
- 【Android应用开发技术:媒体开发】音频
- 浅谈BLE
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- Android使用套接字的几个注意事项
- 两分钟彻底让你明白Android中onInterceptTouchEvent与onTouchEvent(图文)!
- [Android]Android Studio导入第三方工程库,以PullToRefreshViewLibrary为例
- Android studio 打包apk如何重命名apk名称
- Android DiskLruCache 源码解析 硬盘缓存的绝佳方案
- Android IntentService完全解析 当Service遇到Handler