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提 ...
随机推荐
- python auto send email
/*************************************************************************** * python auto send emai ...
- apache开源项目--ApacheDS
ApacheDS (Apache Directory Server)的核心是目录服务,可以保存数据,并对不同类型的数据进行搜索操作.协议的实现在目录服务器顶层工作,提供与数据存储.搜索和检索有关的 I ...
- 【转】Angular运行原理揭秘 Part 1
当你用AngularJS写的应用越多, 你会越发的觉得它相当神奇. 之前我用AngularJS实现了相当多酷炫的效果, 所以我决定去看看它的源码, 我想这样也许我能知道它的原理. 下面是我从源码中找到 ...
- 临时禁用Resharper
Visual Studio 菜单 –> 工具 –> 选项 –> ReSharper –> Suspend按钮
- JPA-一对多关系
JPA中,一对多关系使用@OneToMany标示 关系维护端: package com.yl.demo1.bean.oneTomany; import javax.persistence.Cascad ...
- selenium在chrome上运行报 Element is not clickable at point (1096, 26)
Firefox上正常运行的脚本在chrome上提示Element is not clickable at point (1096, 26).分析原因,首先肯定不是因为页面元素不存在而无法点击.也不是要 ...
- 利用CryptoStream进行加密解密
public class DBSecurity { //sKey sIV这两个自己随意设定,不能外泄 private const string sKey = "11,22,33,43,34, ...
- vi常用命令与设置(不断修改中)
注:前缀':'表示vim命令(命令模式),前缀'$'表示为shell命令,表示Ctrl + W,表示Ctrl + Shift+ 6,无前缀者均为普通模式下的键盘按键.基本的插入与修改: ...
- 基于寄存器的VM
jvm是基于栈的,基于栈的原因是:实现简单,考虑的就是两个地方,局部变量和操作数栈 http://ifeve.com/javacode2bytecode/这几篇文章相当不错. http://redna ...
- javascript设计模式6
单体模式:用来划分命名空间而组织一些方法和属性的对象,如果它能被实例化,只能被实例化一次:但对象不是单体 var Singleton={ attr1:true; attr2:2, method1:fu ...