UI控件--PopWindow
2016-04-02 20:54
429 查看
PopWindow和AlertDialog的使用非常的相似
效果图如下:
自定义布局如下:
代码如下
可以通过判断popupWindow.isShowing()方法,来确定是否已经打开了popWindow,以避免popWindow的重复打开
对自定义控件的点击事件的处理我并未上传,仅仅是一个吐司提示,读者请自行尝试。
第一种显示popWindow的方法
方法表示popWindow放置在哪个控件的下方,以及x和y的偏移量。
第二种显示popWindow的方法
需要加载popWindow的所在的布局的实例,然后设置其父控件,对齐方式,以及x、y的偏移量
效果图如下:
自定义布局如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView_exit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:gravity="center" android:background="#004400" android:layout_gravity="center" android:textSize="40sp" android:text="退出"/> <TextView android:id="@+id/textView_cancal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:background="#990055" android:layout_gravity="center" android:textSize="40sp" android:gravity="center" android:text="取消"/> </LinearLayout>
代码如下
if (!popupWindow.isShowing()){ popupWindow = new PopupWindow(); View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_popwindow, null); TextView textView_exit = (TextView) view.findViewById(R.id.textView_exit); TextView textView_cancal = (TextView) view.findViewById(R.id.textView_cancal); textView_cancal.setOnClickListener(this); textView_exit.setOnClickListener(this); popupWindow.setContentView(view); popupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); // View rootView=LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_main,null); // popupWindow.showAtLocation(rootView,Gravity.BOTTOM,0,0); popupWindow.showAsDropDown(button,0,0); }
可以通过判断popupWindow.isShowing()方法,来确定是否已经打开了popWindow,以避免popWindow的重复打开
对自定义控件的点击事件的处理我并未上传,仅仅是一个吐司提示,读者请自行尝试。
第一种显示popWindow的方法
popupWindow.showAsDropDown(button,0,0)
方法表示popWindow放置在哪个控件的下方,以及x和y的偏移量。
第二种显示popWindow的方法
View rootView=LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_main,null); popupWindow.showAtLocation(rootView,Gravity.BOTTOM,0,0);
需要加载popWindow的所在的布局的实例,然后设置其父控件,对齐方式,以及x、y的偏移量
相关文章推荐
- 第63课:Spark SQL下Parquet内幕深度解密学习笔记
- HD 1159 Common Subsequence (最长公共子序列)
- UI控件--AlertDialog
- Android引导动画库:TourGuide
- POJ 1679 The Unique MST 次小生成树
- POJ 1679 The Unique MST 次小生成树
- 第62课:SparkSQL下的Parquet使用最佳实践和代码实践学习笔记
- ubuntu――How to Install MySQL GUI
- 95. Unique Binary Search Trees II
- LC60 Permutation Sequence
- UITableView的介绍及使用
- ubuntu12.04+ros fuerte 跑ORB_SLAM代码
- DuiLib(2)——几种控件的常规属性介绍
- 4 Java基础语法(switch语句,循环语句(for,while),控制跳转语句(break,return,continue))
- HDU - 5288-OO’s Sequence-数学+分类再二分+枚举+contribution costing
- [LeetCode]Implement Stack using Queues
- JS/html/form/XMLHttpRequest Ajax 批量上传文件/图片的3种方式
- POJ1679 The Unique MST
- <%@ include file=” ”%> 和<jsp:include page=” ” flush=”true”/> 区别
- Unique Binary Search Trees