http://blog.csdn.net/jj120522/article/details/7764183

首先我们看一下新浪微博的效果(其它就是一个dialog):

              

点击title前                                                    点击title后

实现方式:

首先我们要自定义一个dialog

代码如下:

  1. /***
  2. * 自定义dialog
  3. *
  4. * @author jia
  5. *
  6. */
  7. public class MyDialog extends Dialog {
  8. private Window window = null;
  9. /***
  10. *
  11. * @param context
  12. * @param layoutResID
  13. *            配置文件
  14. * @param x
  15. *            显示的x坐标
  16. * @param y
  17. *            显示的y坐标
  18. * @param title
  19. *            集合
  20. */
  21. public MyDialog(final Context context, int layoutResID, int x, int y,
  22. final String[] title) {
  23. super(context, R.style.Transparent);
  24. window = this.getWindow();
  25. window.requestFeature(Window.FEATURE_NO_TITLE);
  26. setContentView(layoutResID);
  27. int width = this.getWindow().getWindowManager().getDefaultDisplay()
  28. .getWidth();
  29. windowDeploy(width / 2, 300, x, y);
  30. show();
  31. }
  32. /***
  33. * 设置窗口显示
  34. *
  35. * @param x
  36. * @param y
  37. * @param dialog_x
  38. * @param dialog_y
  39. */
  40. public void windowDeploy(int dialog_width, int dialog_height, int dialog_x,
  41. int dialog_y) {
  42. window.setBackgroundDrawableResource(android.R.color.transparent); // 设置对话框背景为透明
  43. WindowManager.LayoutParams wl = window.getAttributes();
  44. wl.width = dialog_width;
  45. wl.height = dialog_height;
  46. // wl.alpha = 0.8f;
  47. wl.gravity = Gravity.LEFT | Gravity.TOP; // 不设置的话默认是居中
  48. wl.x = dialog_x - dialog_width / 2; // 要显示的位置x坐标
  49. wl.y = dialog_y;
  50. window.setAttributes(wl);
  51. window.setWindowAnimations(R.style.dialogWindowAnim); // 设置窗口弹出动画
  52. setCanceledOnTouchOutside(true);
  53. }
  54. }

我们只需要在activity中调用即可:

代码片段:

  1. textView.setOnClickListener(new OnClickListener() {
  2. @Override
  3. public void onClick(View v) {
  4. int x_begin = textView.getLeft();
  5. int x_end = textView.getRight();
  6. int y_begin = textView.getTop();
  7. int y_end = textView.getBottom();// 这个是要显示位置的纵坐标
  8. // 获取最中间的x坐标
  9. int x = (x_begin + x_end) / 2;// 这个值也就是屏幕最中间的值,也可以下面这样
  10. // int x=getWindowManager().getDefaultDisplay().getWidth()/2;
  11. // int[] location = new int[2];
  12. // textView.getLocationInWindow(location); // 获取在当前窗口内的绝对坐标
  13. // textView.getLocationOnScreen(location);// 获取在整个屏幕内的绝对坐标
  14. myDialog = new MyDialog(DialogDemoActivity.this,
  15. R.layout.dialog, x, y_end, title);
  16. View view = LayoutInflater.from(DialogDemoActivity.this)
  17. .inflate(R.layout.dialog, null);
  18. listView = (ListView) myDialog.getWindow().findViewById(
  19. R.id.lv_dialog);
  20. listView.setAdapter(new ArrayAdapter<String>(
  21. DialogDemoActivity.this, R.layout.text, R.id.tv_text,
  22. title));
  23. listView.setOnItemClickListener(new OnItemClickListener() {
  24. @Override
  25. public void onItemClick(AdapterView<?> arg0, View arg1,
  26. int arg2, long arg3) {
  27. textView.setText(title[arg2]);
  28. myDialog.cancel();
  29. myDialog = null;
  30. }
  31. });
  32. }
  33. });

实现效果如下:

           

点击前                                                点击后                                             选择                                                   选择后

实现起来也不难,有点要说明一下,这里我们用到了.9.png图片,这个图片会自动根据需要伸展,(重要的是不失真,这点很棒吧,详细介绍请点击连接).

源码下载

android dialog 模拟新浪、腾讯title弹框效果的更多相关文章

  1. popupwindow 模拟新浪、腾讯title弹框效果

    .jpg外部引用 原始文档 MainActivity.java外部引用 原始文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...

  2. 整合 新浪 腾讯 人人 qq空间 分享地址

    function snsShare(snsId, title, content, image, url) { var snsUrl; // 新浪 腾讯 要申请appkey switch (snsId) ...

  3. android WebView将新浪天气为我所用 ------>仅供娱乐

    新浪天气提供了一个网页     http://w.sina.com 浏览器访问: 这效果还可以了哦,直接用webview加载出来,效果也可以了哦,不过,这不是我要的.我不希望在我写的应用里到处铺满si ...

  4. Java 模拟新浪登录 2016

    想学习一下网络爬虫.涉及到模拟登录,查阅了一番资料以后发现大部分都有点过时了,就使用前辈们给的经验,Firefox抓包调试,採用httpclient模拟了一下新浪登录. 不正确之处多多包括.须要的能够 ...

  5. jquery实现隐藏显示层动画效果、仿新浪字符动态输入、tab效果

    已经有两年多没登陆csdn账号了,中间做了些旁的事,可是现在却还是回归程序,但改做前端了,虽然很多东西都已忘得差不多了,但还是应该摆正心态,慢慢来,在前端漫游,做一只快乐双鱼. 路是一步一步走出来的, ...

  6. 【多端应用开发系列1.1.1 —— Android:使用新浪API V2】服务器Json数据处理——Json数据概述

    [前白] 一些基础的东西本系列中就不再详述了,争取尽量写些必不可少的技术要点. 由于本系列把Web Service 构建放到了第二部分,Android项目就采用新浪微博API v2作为服务器端. [原 ...

  7. 类似新浪 腾讯微博字数统计 控制js(区分中英文 符号)

    <script> ; function Q(s) { return document.getElementById(s); } function checkWord(c) { len = ...

  8. HBuilder webApp开发(七)微信/QQ/新浪/腾讯微博分享

    链接 https://blog.csdn.net/zhuming3834/article/details/51706256

  9. 接入新浪、腾讯微博和人人网的Android客户端实例 接入新浪、腾讯微博和人人网的Android客户端实例

    做了个Android项目,需要接入新浪微博,实现时也顺带着研究了下腾讯微博和人人网的Android客户端接入,本文就跟大家分享下三者的Android客户端接入方法. 一.实例概述 说白了,接入微博就是 ...

随机推荐

  1. MongoDB学习与BUG解答

    简单介绍: MongoDb也是NoSQL中的一种,并且是应用比较火的一门解决高效处理数据的技术. 网上说它是介于关系数据库 和非关系数据库之间的产品,它是非关系数据库中最丰富的,最像关系数据的. Q: ...

  2. oracle 简述

    1.数据库有很多的管理工具,Sqlplus是最好的管理工具. 2.sql语句是学习中最难的部分,如何编写出高效的sql 语句是我们的目标 3.oracle的日常最终要的工作就是备份,永远是备份,有数据 ...

  3. 小菜鸟学 Spring-bean scope (一)

    this information below just for study record of mine. 默认情况下:Spring 创建singleton bean 以便于错误能够被发现. 延迟加载 ...

  4. localStorage和sessionStorage的区别

    //在chrome测试的结果; 知识点1:localStorage和sessionStorage的区别; localStorage生命周期是永久,这意味着除非用户显示在浏览器提供的UI上清除local ...

  5. __name__和__main的含义

    if __name__ == "__main__": main() This module represents the (otherwise anonymous) scope i ...

  6. list 内部方法

    代码 #list内部方法 l=['a','9','c','a','3','7'] print(dir(l)) l.append('v') print(l)#append(self, p_object) ...

  7. Xcode 6以上版本如何创建一个空的工程(Empty Application)

    Xcode 6 正式版里面没有Empty Application这个模板,这对于习惯了纯代码编写UI界面的程序员来说很不习惯. 有高手给出了一个解决方法是,把Xcode 6 beta版里面的模板复制过 ...

  8. [NOIP2011] 提高组 洛谷P1311 选择客栈

    题目描述 丽江河边有n 家很有特色的客栈,客栈按照其位置顺序从 1 到n 编号.每家客栈都按照某一种色调进行装饰(总共 k 种,用整数 0 ~ k-1 表示),且每家客栈都设有一家咖啡店,每家咖啡店均 ...

  9. 洛谷P1262 间谍网络

    本来只想刷道小题,没想到还有点麻烦 题目描述 由于外国间谍的大量渗入,国家安全正处于高度的危机之中.如果A间谍手中掌握着关于B间谍的犯罪证据,则称A可以揭发B.有些间谍收受贿赂,只要给他们一定数量的美 ...

  10. NOIP2008普及组题解

    NOIP2008普及组题解 从我在其他站的博客直接搬过来的 posted @ 2016-04-16 01:11 然后我又搬回博客园了233333 posted @ 2016-06-05 19:19 T ...