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提 ...
随机推荐
- SHA-1加密
/** * SHA-1加密 * @param strSrc 要加密的字符串 * @return 加密后的字符串 */ public static String SHAEncrypt(String st ...
- c语言中静态区,栈,堆的理解
对于程序员,一般来说,我们可以简单的理解为内存分为三个部分:静态区,栈,堆. 很多书没有把把堆和栈解释清楚,导致初学者总是分不清楚. 其实堆栈就是栈,而不是堆. 堆的英文是heap:栈的英文是stac ...
- 【转】angular Ajax请求
1.http请求 基本的操作由 $http 服务提供.它的使用很简单,提供一些描述请求的参数,请求就出去了,然后返回一个扩充了 success 方法和 error 方法的 promise对象(下节介绍 ...
- XMPP 初探
最近刚好有机会碰到XMPP,把一些学习心得记录在这边. XMPP(Extensible Messageing and Presence Protocol)是一种IM的通讯协定,其前身为Jabber,后 ...
- Spring--通过注解来配置bean
Spring通过注解配置bean 基于注解配置bean 基于注解来配置bean的属性 在classpath中扫描组件 组件扫描(component scanning):Spring能够从classpa ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.3.1
Let $A=A_1\oplus A_2$. Show that (1). $W(A)$ is the convex hull of $W(A_1)$ and $W(A_2)$; i.e., the ...
- spring+mybatis 多数据源整合
<!-- 数据源配置 --> <bean id="ds1" class="org.apache.commons.dbcp.BasicDataSour ...
- STL(pair map set vector priority_queue) poj 3297
POJ 3297 算法竞赛初级杂烩包 题意:学生选课,没个学生只能选一门课.大写字符是课的名字,小写是人名.如果课程后面有多个相同名字算一个,如果一个人选多门课,则他选不上课,输出课和每门课选课人数 ...
- ubuntu源码安装R语言
下载后解压完,进入开始配置: ./configure --enable-R-shlib 报错: configure: error: con--with-readline=yes (default) a ...
- 第九章、文件与文件系统的压缩与打包 3. 打包命令: tar
打包命令: tar gzip 与 bzip2 也能够针对目录来进行压缩, 不过,这两个命令对目录的压缩指的是『将目录内的所有文件 "分别" 进行压缩』! 将多个文件或目录包成一个大 ...