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提 ...
随机推荐
- Android 主题动态切换框架:Prism
Prism(棱镜) 是一个全新的 Android 动态主题切换框架,虽然是头一次发布,但它所具备的基础功能已经足够强大了!本文介绍了 Prism 的各种用法,希望对你会有所帮助,你也可以对它进行扩展, ...
- 【转】AngularJS路由和模板
1. AngularJS路由介绍 AngularJS路由功能是一个纯前端的解决方案,与我们熟悉的后台路由不太一样.后台路由,通过不同的URL会路由到不同的控制器上(controller),再渲染(re ...
- PHP错误:Forbidden You don't have permission to access / on this server.
今天在测试一个php程序的时候,发现这个问题: Forbidden You don't have permission to access / on this server. 开始的时候我是用http ...
- Runnable、Callable、Future和FutureTask用法
http://www.cnblogs.com/dolphin0520/p/3949310.html java 1.5以前创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable ...
- REST API TESTING
在敏捷开发过程中 每隔两周就是一个sprint,,, 在上个sprint中,任务就是REST API TESTING 因为以前没做过API 测试,不懂,然后经过询问查找 终于知道,需要发送请求,然后获 ...
- Linux shell命令
一.删除监听指定端口的进程: lsof -ti: 80 | xargs kill -9 -t: 输出pid -i:查看指定端口占用情况 二.查看可执行文件动态链接库相关信息 ldd <可执行文件 ...
- MapReduce:Shuffle过程的流程
Shuffle过程是MapReduce的核心,Shuffle描述着数据从map task输出到reduce task输入的这段过程. 1.map端
- algorithm: heap sort in python 算法导论 堆排序
An Python implementation of heap-sort based on the detailed algorithm description in Introduction to ...
- bzoj 1176 Mokia(CDQ分治,BIT)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=96974 [题意] 定义查询操作与修改操作:1 x y z 为 ...
- Extjs4 MVC Controlller中refs使用
前面几篇写了一下mvc的整体使用方法,今天写一下controller中refs的试用,refs的作用类似于我们告诉controller我们的一个元素的别名,既alias,那么controller就会为 ...