android PopupWindow使用实例
注:点空白或菜单外隐藏popupwindow菜单;
但是,若点击有点击事件的组件则要再写代码手动隐藏;
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (mMenuPPW!=null){
if (mMenuPPW.isShowing())
mMenuPPW.dismiss();
}
return super.onTouchEvent(event); }

.java
private PopupWindow mMenu;
public void CreatMenu(View view) {
if (mMenu == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.popuppindow_group,
null, false);
LinearLayout lytRequest = (LinearLayout) v.findViewById(R.id.lyt_pw_groupmember_request);
lytRequest.setOnClickListener(this);
LinearLayout lytExit = (LinearLayout) v.findViewById(R.id.lyt_pw_groupmember_exit);
lytExit.setOnClickListener(this);
mMenu = new PopupWindow(v);
// moreMenu.setWidth(300);
mMenu.setWidth(LayoutParams.WRAP_CONTENT);
mMenu.setHeight(LayoutParams.WRAP_CONTENT);
mMenu.showAsDropDown(view);
} else {
if (mMenu.isShowing()) {
mMenu.dismiss();
} else {
mMenu.showAsDropDown(view);
}
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.lyt_activitygroupmembers_menu:
CreatMenu(v);
break;
case R.id.lyt_pw_groupmember_request:
Toast.makeText(this, "request", Toast.LENGTH_SHORT).show();
mMenu.dismiss();
break;
case R.id.lyt_pw_groupmember_exit:
Toast.makeText(this, "exit", Toast.LENGTH_SHORT).show();
mMenu.dismiss();
break;
}
}
.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" > <LinearLayout
android:id="@+id/lyt_pw_groupmember_request"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" > <TextView
android:id="@+id/TextView03"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="left|center"
android:text="request"
android:textSize="18sp" /> <TextView
android:id="@+id/TextView04"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="@android:color/darker_gray"
android:text="TextView" /> </LinearLayout> <LinearLayout
android:id="@+id/lyt_pw_groupmember_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" > <TextView
android:id="@+id/TextView02"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="left|center"
android:text="exit"
android:textSize="18sp" /> </LinearLayout> </LinearLayout> </RelativeLayout>
注:mMenu.showAsDropDown(view, 0, 16);即偏移view,x,y轴的间距
android PopupWindow使用实例的更多相关文章
- Android PopupWindow使用方法小结
前几天要用到PopupWindow,一时竟想不起来怎么用,赶紧上网查了查,自己写了个demo,并在此记录一下PopupWindow的用法. 使用场景 PopupWindow,顾名思义,就是弹窗,在很多 ...
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- Android PopupWindow的使用和分析
Android PopupWindow的使用和分析 PopupWindow使用 PopupWindow这个类用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activi ...
- android widget 开发实例 : 桌面便签程序的实现具体解释和源代码 (上)
如有错漏请不吝拍砖指正,转载请注明出处,很感谢 桌面便签软件是android上经常使用软件的一种,比方比較早的Sticky Note,就曾很流行, Sticky Note的介绍能够參见 http:// ...
- Android PopupWindow的使用技巧(转)
Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...
- Android进阶(二十三)Android开发过程之实例讲解
Android开发过程之实例讲解 前言 回过头来审视之前做过的Android项目,发觉自己重新开发时忽然间不知所措了,间隔了太长时间没有开发导致自己的Android技能知识急剧下降.温故而知新. 废话 ...
- [转]Android:布局实例之模仿QQ登录界面
Android:布局实例之模仿QQ登录界面 预览图: 准备: 1.找到模仿对象 QQ登陆界面UI下载>>>>> 2.导入工程 3.查看布局结构和使用控件 其对应效果图分布 ...
- Android 应用开发实例之情景模式
2013-07-01 Android 应用开发实例 1. 情景模式 使用TabHost来实现主界面的布局. 设置一组RadioButton来切换不同的情景模式. 对比普通情景模式,定时情景模式需要加上 ...
- Android:布局实例之模仿QQ登录界面
预览图: 准备: 1.找到模仿对象 QQ登陆界面UI下载>>>>> 2.导入工程 3.查看布局结构和使用控件 其对应效果图分布为 4.分析样式选择器 下拉箭头2种样式:点 ...
随机推荐
- 【FOL】第九周
不知不觉又是三周过去了. 这几周忙了一下,其他时间全都在搞服务端,简直是酸爽的不行...不过还好出了些成果. 目前服务端有: 1.版本服务:游戏版本更新 2.账号服务:用户身份验证,返回各种连接(代理 ...
- 在VS 2012 配置SDL
一.链接:http://pan.baidu.com/s/1kVaWteR 密码:zt81 下载两个文件夹.(如果不行就到 SDL官网 https://www.libsdl.org/ 和 SDL2_im ...
- Spring4学习笔记2-配置集合属性
1 可使用<list> <map> <set>等来配置集合属性 2 List <!-- 配置List属性 --> <bean id="p ...
- JPA persistence
Play provides a set of very useful helpers to simplify the management of your JPA entities. Note tha ...
- 免费 PSD 下载: 20个精美的登录和注册表单
注册表单有许多不同的形状和尺寸,有的只是单个的输入框,有的则需要多个步骤.登录表单的设计将定义网站的性质,因此它应进行针对性的设计.下面的列表提供了20个醒目的登录和注册表单设计为您提供灵感. 您可能 ...
- 从0开始学angularjs-笔记04
由于公司加班,刚到家不久,然而却毫无睡意,可能是老了吧--- 不废话了,没睡意那就做点有意义的事情吧,继续我们的angular学习之路,深夜博文,希望能造福大家! 这次我们来详细讲解angular的双 ...
- 学习笔记:腾讯云——服务器mysql操作
1.进入数据库 (注意:在linux系统下要进入mysql所在的文件夹下才能打开数据库) 操作1:进入到指定目录下 命令行:cd /opt/lampp/bin 操作2:进入到数据库 命令行:./mys ...
- ECMAScript对文件夹图片幻灯片播放
代码如下: var curContext = null; var curWeb = null; var picListTitle = "PictureLib"; var folde ...
- UIView中的坐标转换
在使用 UITableViewCell 的frame属性获取origin得到的坐标是不变的. 也就是说如果UITableView初始化完毕后,每个cell的坐标是固定的,x不变,y 随index递增的 ...
- 微信公众号里打开链接下载APP
嵌入这样的代码 <a href="http://a.app.qq.com/o/simple.jsp?pkgname=com.violationquery" target=&q ...