2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报
 分类:
Andriod之路(72) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载请指明出处 :http://blog.csdn.net/hellohhj/article/details/37600469

主要介绍一下popupWindow的简单用法,包括在控件的上方、正上方、下方、正下方、左方、正左方、右方、正右方以及在屏幕中间显示等等。。。

希望对大家有帮助

主要代码如下:

  1. private void showPopUp(View v) {
  2. LinearLayout layout = new LinearLayout(this);
  3. layout.setBackgroundColor(Color.GRAY);
  4. TextView tv = new TextView(this);
  5. tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  6. LayoutParams.WRAP_CONTENT));
  7. tv.setText("我最亲爱的。。。。。我最亲爱的。。。。。我最亲爱的。。。。。我最亲爱的。。。。。我最亲爱的。。。。。我最亲爱的。。。。。我最亲爱的。。。。。我最亲爱的。。。。。");
  8. tv.setTextColor(Color.WHITE);
  9. layout.addView(tv);
  10. popupWindow = new PopupWindow(layout, 250, 200);
  11. popupWindow.setFocusable(true);
  12. popupWindow.setOutsideTouchable(true);
  13. popupWindow.setBackgroundDrawable(new BitmapDrawable());
  14. int[] location = new int[2];
  15. v.getLocationOnScreen(location);
  16. int v_with = v.getWidth();
  17. int v_height = v.getHeight();
  18. // 屏幕中央
  19. popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
  20. ;
  21. // // 上方
  22. // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0],
  23. // location[1] - popupWindow.getHeight());
  24. // // 正上方
  25. // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY,
  26. // location[0] + Math.abs((v_with - popupWindow.getWidth()) / 2),
  27. // location[1] - popupWindow.getHeight());
  28. // // 下方
  29. // popupWindow.showAsDropDown(v);
  30. // // 正下方
  31. // popupWindow.showAsDropDown(v,
  32. // Math.abs((v_with - popupWindow.getWidth()) / 2), 0);
  33. //
  34. // // 左方
  35. // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]
  36. // - popupWindow.getWidth(), location[1]);
  37. // //正左方
  38. // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]
  39. // - popupWindow.getWidth(), location[1]-Math.abs((v_height -
  40. // popupWindow.getHeight()) / 2));
  41. // // 右方
  42. // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY,
  43. // location[0] + v.getWidth(), location[1]);
  44. // 正右方
  45. // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY,
  46. // location[0] + v.getWidth(), location[1]-Math.abs((v_height -
  47. // popupWindow.getHeight()) / 2));
  48. }

下面附上源码地址 :http://download.csdn.net/detail/hellohhj/7612275

 
0
0
 
  相关文章推荐
 
查看评论
  暂无评论

 
 
您还没有登录,请[登录][注册]
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
 
 
 
 
    个人

(转载) popupWindow 指定位置上的显示的更多相关文章

  1. android学习——popupWindow 在指定位置上的显示

    先看效果图,免得浪费大家时间,看是不是想要的效果 . 直接上代码 ,核心方法. [java] view plaincopy private void showPopupWindow(View pare ...

  2. popupWindow 在指定位置上的显示

    先看效果图,免得浪费大家时间,看是不是想要的效果 . 直接上代码 ,核心方法. private void showPopupWindow(View parent) { if (popupWindow  ...

  3. 问题:asp.net 点击button按钮调到页面顶部;结果:asp.net点击一个按钮,使页面跳转到本面页上的指定位置

    asp.net点击一个按钮,使页面跳转到本面页上的指定位置 (2011-04-19 16:46:51) 转载▼ 标签: it   最近在做一个项目. 用到标题所说的功能. 实现方法: 1.在aspx中 ...

  4. $.messager.show扩展:指定位置显示

    扩展了个$.messager.showBySite,根据舍得的位置显示$.messager.show.代码如下: /** * 指定位置显示$.messager.show * options $.mes ...

  5. 【转载】C#使用InsertRange方法往ArrayList集合指定位置插入另一个集合

    在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,ArrayList集合可存储多种数据类型的对象.在实际的开发过程中,我们可以使用InsertRange方法在ArrayList集合指 ...

  6. 【转载】C#中string类使用Remove方法来移除指定位置的字符

    在C#的字符串操作过程中,有时候需要将字符串中指定位置的字符移除,此时就可能使用到字符串类string类中的Remove方法,此方法允许指定移除开始的开始的索引位置,以及移除的长度信息等,共有2个重载 ...

  7. 【转载】C#中使用List集合的Insert方法在指定位置插入数据

    在C#的List集合等数据类型变量中,我们可以使用List集合的Insert方法在指定的索引位置插入一个新数据,例如指定在List集合的第一个位置写入一个新数据或者在List集合的中间某个位置插入个新 ...

  8. postman上传excel,java后台读取excel生成到指定位置进行备份,并且把excel中的数据添加到数据库

    最近要做个前端网页上传excel,数据直接添加到数据库的功能..在此写个读取excel的demo. 首先新建springboot的web项目 导包,读取excel可以用poi也可以用jxl,这里本文用 ...

  9. 解决使用 Eruda 绑定 dom 未在指定位置显示问题

    前言 开发项目中,使用到 Eruda 打印控制台信息显示 文档:https://github.com/liriliri/eruda 安装 Eruda npm install eruda --save ...

随机推荐

  1. pymysql.err.ProgrammingError: (1064)(字符串转译问题)

    代码: sql = "insert into dm_copy(演出类型,演出场馆,剧目名称,演出地点,演出时间,演出票价,演出团体,创建时间, url)values('%s','%s','% ...

  2. win10下一分钟快速搭建rtmp推流服务器

    为了让大家少踩笔者踩过的坑,目前将工作中搭建rtmp推流服务器的步骤总结如下: 步骤1: 下载 nginx 1.7.11.3 Gryphon 下载链接: http://nginx-win.ecsds. ...

  3. C#第十节课

    类 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Thr ...

  4. Git 基础教程 之 添加、提交

    一, 编写一个名为readme.txt文件,放入pythonwork目录下 ①   手动新建 ②   使用命令: a. touch readme.txt   b. vim readme.txt PS: ...

  5. vue中访问数据接口的配置

    业务API接口地址: http://localhost:3816/api/ 前端UI浏览地址:http://127.0.0.1:8080/#/home 由于同源策略的问题: 需要配置代理: 在开发环境 ...

  6. POJ 3762 The Bonus Salary!

    The Bonus Salary! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Origi ...

  7. 0209利用innobackupex进行简单数据库的备份

    利用innobackupex进行简单数据库的备份yum install perl-DBIyum install perl-DBD-MySQLyum install perl-Time-HiResyum ...

  8. 数据库--ACID特性

    事务的ACID属性 原子性(Atomicity) 原子性是指事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不发生. 一致性(Consistency) 事务必须使数据库从一个一致性状态变换 ...

  9. A. Feed the cat

    A. Feed the cat time limit per test: 1 second memory limit per test: 256 megabytes input: standard i ...

  10. @Zookeeper可视化工具。 ZK 安装 node-zk-browser。2015.10.22亲测可用

    zookeeper基本是基于API和console进行znode的操作,并没有一个比较方便的操作界面,这里也发现了taobao 伯岩写的一个工具,可以比较方便的查询zookeeper信息. 工具的开发 ...