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. 数据清理,预处理 pandas dataframe 操作技巧 总结

    dsoft2 = data1.loc[(data1['程'] == "轻") | (data1['程'] == "中")]设置x下标plt.xticks(np. ...

  2. eas之去掉关闭eas页面时校验是否修改的提示

    EditUI-------> public boolean checkBeforeWindowClosing() {            boolean b = super.checkBefo ...

  3. python实现RGB转化为灰度图像

    问题: 我正尝试使用matplotlib读取RGB图像并将其转换为灰度.在matlab中,我使用这个: 1 img = rgb2gray(imread('image.png')); 在matplotl ...

  4. 【日常学习】【搜索/递归】codevs2802 二的幂次方题解

    转载请注明出处 [ametake版权全部]http://blog.csdn.net/ametake欢迎来看 题目描写叙述 Description 不论什么一个正整数都能够用2的幂次方表示. 比如:13 ...

  5. 几种new

    http://www.cnblogs.com/luxiaoxun/archive/2012/08/10/2631812.html new .operator new 和 placement new 区 ...

  6. Ubuntu镜像文件下载

    Ubuntu镜像文件下载 http://www.traffictool.net/vmware/ubuntu1404t.html 下载之后可以使用vmplayer启动: user/password ro ...

  7. ArcEngine 地图导航 查找路径 经纬度坐标导航 最优路径分析

    本文来自CSDN博客.转载请标明出处 http//blog.csdn.net/zdb330906531 需求:依据经纬度坐标.取得两个起点与终点,显示最优路径实现导航. 參考官方样例后.我在arcMa ...

  8. [Cypress] Stub Network Requests in a Cypress Test

    To keep our tests fast and easily repeatable, it makes sense to create many integration tests and fe ...

  9. iOS音频播放之AudioQueue(一):播放本地音乐

    AudioQueue简单介绍 AudioStreamer说明 AudioQueue具体解释 AudioQueue工作原理 AudioQueue主要接口 AudioQueueNewOutput Audi ...

  10. 科普:alphago是什么

    鉴于大部分人类对alphago的认识: 1:Alphago有什么了不起的?不就是算得快吗.ibm早在20年前就通过象棋战胜人类了.又是Google的一次营销. 2:alphago 实现人工智能了,电脑 ...