android Popupwindow 的一个demo源码
一直想用一下PopupWindow,就是苦于没有demo,自己去研究有太懒,刚好最近研究推送,下载了一个腾讯信鸽的demo,里面用到了一个PopupWindow,效果还不错,弄下来记录一下:
1.核心java代码如下:
View v = LayoutInflater.from(this).inflate(R.layout.menu_item, null); //加载popupwindow的自定义view
final PopupWindow pw = new PopupWindow(v, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
pw.setContentView(v);
pw.setOutsideTouchable(true);
pw.setFocusable(true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.showAsDropDown(findViewById(R.id.img_right)); //现在是img_right这个view的下面
2.下面是menu_item这个layout的内容
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/qq_dimen_330px"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@android:color/transparent"
android:orientation="vertical" > <LinearLayout
android:layout_width="@dimen/qq_dimen_330px"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@android:color/black"
android:orientation="vertical" > <TextView
android:id="@+id/action_device_token"
android:layout_width="match_parent"
android:layout_height="@dimen/qq_dimen_80px"
android:gravity="center"
android:singleLine="true"
android:text="@string/action_device_token"
android:textColor="@android:color/white" /> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/fuxk_base_divide_line_color" /> <TextView
android:id="@+id/action_help_center"
android:layout_width="match_parent"
android:layout_height="@dimen/qq_dimen_80px"
android:gravity="center"
android:singleLine="true"
android:text="@string/action_help_center"
android:textColor="@android:color/white" /> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/fuxk_base_divide_line_color" /> <TextView
android:id="@+id/action_about_us"
android:layout_width="match_parent"
android:layout_height="@dimen/qq_dimen_80px"
android:gravity="center"
android:singleLine="true"
android:text="@string/action_about_us"
android:textColor="@android:color/white" /> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/fuxk_base_divide_line_color" /> <TextView
android:id="@+id/action_clear"
android:layout_width="match_parent"
android:layout_height="@dimen/qq_dimen_80px"
android:gravity="center"
android:singleLine="true"
android:text="@string/action_clear"
android:textColor="@android:color/white" /> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/fuxk_base_divide_line_color" /> <TextView
android:id="@+id/action_setting"
android:layout_width="match_parent"
android:layout_height="@dimen/qq_dimen_80px"
android:gravity="center"
android:singleLine="true"
android:text="@string/action_setting"
android:textColor="@android:color/white" /> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/fuxk_base_divide_line_color" /> <TextView
android:id="@+id/action_diagnosis"
android:layout_width="match_parent"
android:layout_height="@dimen/qq_dimen_80px"
android:gravity="center"
android:singleLine="true"
android:text="@string/action_diagnosis"
android:textColor="@android:color/white" />
</LinearLayout> </RelativeLayout>
对应的布局效果为:
这个地方比较好的是,不用自己去制定popupwindow的显示位置了,直接在layout中定位显示,感觉会比自己代码设定位置好些
android Popupwindow 的一个demo源码的更多相关文章
- Android Studio 的蓝牙串口通信(附Demo源码下载)
根据相关代码制作了一个开源依赖包,将以下所有的代码进行打包,直接调用即可完成所有的操作.详细说明地址如下,如果觉得有用可以GIthub点个Star支持一下: 项目官网 Kotlin版本说明文档 Jav ...
- Android Small插件化框架源码分析
Android Small插件化框架源码分析 目录 概述 Small如何使用 插件加载流程 待改进的地方 一.概述 Small是一个写得非常简洁的插件化框架,工程源码位置:https://github ...
- Android IntentService使用介绍以及源码解析
版权声明:本文出自汪磊的博客,转载请务必注明出处. 一.IntentService概述及使用举例 IntentService内部实现机制用到了HandlerThread,如果对HandlerThrea ...
- android应用商店完整版源码
这个是从一个安卓学习的网站上转载过来的,android应用商店完整版源码,大家可以看看一下吧. _op><ignore_js_op> <ignore_js_op>< ...
- Android版的疯狂猜图游戏源码完整版分享
这个游戏源码是在安装教程网那么分享过来的,Android版的疯狂猜图游戏源码完整版分享,也是本人之前很早以前发的一款游戏源码的,大家如果想了解一下,可以看看吧,不说多了,上一个图先吧. > ...
- 如何在Exe和BPL插件中实现公共变量共享及窗口溶入技术Demo源码
如何在Exe和BPL插件中实现公共变量共享及窗口溶入技术Demo源码 1.Delphi编译方式介绍: 当我们在开发一个常规应用程序时,Delphi可以让我们用两种方式使用VCL,一种是把VCL中的申明 ...
- [c#]asp.net开发微信公众平台(7)前6篇的整体框架demo源码
这里给出的demo是具备整体框架的微信公众平台源码, 所谓demo就是拿过去就可以直接演示使用的东西, 当然不会具备非常详细的具体到业务层面.数据层面的东西, 每个人都可以在此基础上自由发挥, 只 ...
- Asp.net MVC集成Google Calendar API(附Demo源码)
Asp.net MVC集成Google Calendar API(附Demo源码) Google Calendar是非常方便的日程管理应用,很多人都非常熟悉.Google的应用在国内不稳定,但是在国外 ...
- 实现简单的手写涂鸦板(demo源码)
在一些软件系统中,需要用到手写涂鸦的功能,然后可以将涂鸦的结果保存为图片,并可以将"真迹"通过网络发送给对方.这种手写涂鸦功能是如何实现的了?最直接的,我们可以使用Windows提 ...
随机推荐
- UVA 753 A Plug for UNIX 电器插座(最大基数匹配,网络流)
题意: 给n个插座,m个设备(肯定要插电了),k种转换头可无限次使用(注意是单向的),问有多少设备最终是不能够插上插座的? 分析: 看起来就是设备匹配插座,所以答案不超过m.这个题适合用网络流来解. ...
- Zen Coding support in WebStorm/PhpStorm
With the last WebStorm/PhpStorm EAP you can edit HTML and CSS code really fast usingZen Coding featu ...
- 实现sqrt()函数
求一个正数N的开方, 并且可以指定精度, 要求不能用库函数sqrt 方法一:如下所示,先求sqrt(N)的整数部分,再求小数点后1位,2位 ... ... 方法二:牛顿迭代法,根据公式 Ai+1 = ...
- socket基本操作
我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览器浏览网页时,浏览器的进程怎么与web服务器通信的?当你用QQ聊天时,QQ进程怎么与服务器或你好友所在的QQ进程通信?这些都得靠so ...
- 使用selector修改TextView中字体的颜色
selector想必大家都用过了,但是在修改字体的颜色的时候还是要细心. 我们在TextView中设置字体颜色一般使用 android:textColor="@color/red" ...
- Jmeter初步使用--Jmeter安装与使用
由于jmeter是开源的性能测试工具,但是使用的人较少,网络上相关资料不全面,需要自己去揣摩,因此,小编就把自己在用Jmeter时的一些小结总结出来.而loadrunner工具是商业软件,网上通常都是 ...
- python 遇到 syntaxerror: non-ascii character '/xd6' in file 我 教你解决 (python问题)(转)
遇到标题上的问题,按照我的解决广方案来吧 ===================================== (一) 用记事本创建一个文件ChineseTest.py,默认ANSI: s = ...
- 常规页生命周期(class0620)
常规页声明周期阶段 阶段 说明 页请求 开始 页初始化 加载 验证 回发事件处理 卸载 生命周期事件 页事件 典型使用
- input子系统 KeyPad-Touch上报数据格式与机制
-----------------------------------------------------------------------本文系本站原创,欢迎转载!转载请注明出处:http://b ...
- 如何为可扩展系统进行Java Socket编程
从简单I/O到异步非阻塞channel的Java Socket模型演变之旅 上世纪九十年代后期,我在一家在线视频游戏工资工作,在哪里我主要的工作就是编写Unix Unix Berkley Socket ...