popupWindow 在指定位置上的显示
先看效果图,免得浪费大家时间,看是不是想要的效果 。

直接上代码 ,核心方法。
- private void showPopupWindow(View parent) {
- if (popupWindow == null) {
- LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = layoutInflater.inflate(R.layout.group_list, null);
- lv_group = (ListView) view.findViewById(R.id.lvGroup);
- Collections.reverse(groups);
- GroupAdapter groupAdapter = new GroupAdapter(this, groups);
- lv_group.setAdapter(groupAdapter);
- popupWindow = new PopupWindow(view, 200, 220);
- }
- popupWindow.setFocusable(true);
- popupWindow.setOutsideTouchable(true);
- // 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
- popupWindow.setBackgroundDrawable(new BitmapDrawable());
- WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
- int xPos = -popupWindow.getWidth() / 2
- + getCustomTitle().getCenter().getWidth() / 2;
- popupWindow.showAsDropDown(parent, xPos, 4);
- lv_group.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view,
- int position, long id) {
- loadNew(((StringItem)(groups.get(position))).getId());
- if (popupWindow != null)
- popupWindow.dismiss();
- }
- });
- }
这篇是转载的 。
popupWindow 在控件的各个方向上的显示(上、下、左、右),主要用到popupWindow 的showAtLocation()方法:
在控件的上方:
- private void showPopUp(View v) {
- LinearLayout layout = new LinearLayout(this);
- layout.setBackgroundColor(Color.GRAY);
- TextView tv = new TextView(this);
- tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
- tv.setText("I'm a pop -----------------------------!");
- tv.setTextColor(Color.WHITE);
- layout.addView(tv);
- popupWindow = new PopupWindow(layout,120,120);
- popupWindow.setFocusable(true);
- popupWindow.setOutsideTouchable(true);
- popupWindow.setBackgroundDrawable(new BitmapDrawable());
- int[] location = new int[2];
- v.getLocationOnScreen(location);
- popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1]-popupWindow.getHeight());
- }
在控件的其他方向上显示只需修改最后一行代码即可,如:
下方:popupWindow.showAsDropDown(v);
左边:
- popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);
右边:
- popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
popupWindow 在指定位置上的显示的更多相关文章
- android学习——popupWindow 在指定位置上的显示
先看效果图,免得浪费大家时间,看是不是想要的效果 . 直接上代码 ,核心方法. [java] view plaincopy private void showPopupWindow(View pare ...
- (转载) popupWindow 指定位置上的显示
popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报 分 ...
- 手把手教popupWindow从下往上,以达到流行效果
效果如图所看到的,点击開始button,popWindow从下往上出来,再点击popWindow外面,popWindow又从上往下消失 能够看出来,上面的popupWindow是半透明的,后面我会细说 ...
- [问题解决]Android7.0上PopupWindow的showAsDropDown位置问题
[问题解决]Android7.0上PopupWindow的showAsDropDown位置问题 /** * Created by diql on 2017/02/16. */ 问题说明 我的popup ...
- $.messager.show扩展:指定位置显示
扩展了个$.messager.showBySite,根据舍得的位置显示$.messager.show.代码如下: /** * 指定位置显示$.messager.show * options $.mes ...
- 问题:asp.net 点击button按钮调到页面顶部;结果:asp.net点击一个按钮,使页面跳转到本面页上的指定位置
asp.net点击一个按钮,使页面跳转到本面页上的指定位置 (2011-04-19 16:46:51) 转载▼ 标签: it 最近在做一个项目. 用到标题所说的功能. 实现方法: 1.在aspx中 ...
- postman上传excel,java后台读取excel生成到指定位置进行备份,并且把excel中的数据添加到数据库
最近要做个前端网页上传excel,数据直接添加到数据库的功能..在此写个读取excel的demo. 首先新建springboot的web项目 导包,读取excel可以用poi也可以用jxl,这里本文用 ...
- 解决使用 Eruda 绑定 dom 未在指定位置显示问题
前言 开发项目中,使用到 Eruda 打印控制台信息显示 文档:https://github.com/liriliri/eruda 安装 Eruda npm install eruda --save ...
- shell如何在指定文件的指定位置后面添加内容
最近工作中遇到一个问题,想在某个文件的指定位置后面添加一个标志位,要求在shell脚本里实现. 问题说明: 想在sys_config.fex文本的某个字符串后面添加一个flag 例如:sys_conf ...
随机推荐
- Action.c(37):Error-27791:Server"192.168.2.111" has shut down the connection paematurely
1)测试的时候最好应用干净的测试环境,即:清楚一切可能干扰的对象:2)如果出了这种错误,要认真的去排查错误,不单单找找脚本,或者[b][url=http://www.ltesting.net/html ...
- 关于Unity中粒子效果的使用
粒子效果1: 游戏中会有很炫酷的特效,比如爆炸,水花,火焰等;2: unity提供粒子编辑器,方便特效人员来开发很炫酷的特效;3.粒子效果一般有专门的粒子特效师来做,我们只需要拿来用就好了,很多参数没 ...
- Spring JMS 官方文档学习
最后部分的XML懒得写了,因为个人更倾向于JavaConfig形式. 为知笔记版本见这里,带格式~ 做了一个小demo,放到码云上了,有兴趣的点我. 说明:需要先了解下JMS的基础知识. 1.介绍 S ...
- C语言中的循环语句练习
注:练习题目均出自<明解C语言 入门篇> 一.do语句 1,求多个整数的和及平均值 #include<stdio.h> int main(void) { ; //和 ; //整 ...
- 详解Paste deploy
原创作品,转载注明本文出处:http://www.cnblogs.com/Security-Darren/p/4087587.html 谈到WSGI,就免不了要了解paste,其中paste depl ...
- JS 在火狐浏览器下关闭弹窗
1.首先,要确定火狐设置是否允许通过JS代码window.close()方法关闭标签. 确定方式如下: 在Firefox地址栏里输入 about:config 在配置列表中找到dom. ...
- xml根据属性去重。如csprj去重
public static void distinct(string filePath) { //1.创建XML文档对象 XmlDocument doc = new XmlDocument(); // ...
- 【转】在64位windows下使用instsrv.exe和srvany.exe创建windows服务
本文转自:https://www.iflym.com/index.php/computer-use/201205020001.html 在32位的windows下,包括windows7,windows ...
- utf16编码格式
UTF-16是Unicode字符集的一种转换方式,即把Unicode的码位转换为16比特长的码元串行,以用于数据存储或传递.UTF-16编码规则如下: 2.2.1 从U+D800到U+DFFF的码位( ...
- [iOS]XCODE5升级之路
1.Code Sign error: 解决方案:重新下载并安装Provisioning profile 2.错误:Undefined symbols for architecture armv ...