android dialog 模拟新浪、腾讯title弹框效果
http://blog.csdn.net/jj120522/article/details/7764183
首先我们看一下新浪微博的效果(其它就是一个dialog):

点击title前 点击title后
实现方式:
首先我们要自定义一个dialog
代码如下:
- /***
- * 自定义dialog
- *
- * @author jia
- *
- */
- public class MyDialog extends Dialog {
- private Window window = null;
- /***
- *
- * @param context
- * @param layoutResID
- * 配置文件
- * @param x
- * 显示的x坐标
- * @param y
- * 显示的y坐标
- * @param title
- * 集合
- */
- public MyDialog(final Context context, int layoutResID, int x, int y,
- final String[] title) {
- super(context, R.style.Transparent);
- window = this.getWindow();
- window.requestFeature(Window.FEATURE_NO_TITLE);
- setContentView(layoutResID);
- int width = this.getWindow().getWindowManager().getDefaultDisplay()
- .getWidth();
- windowDeploy(width / 2, 300, x, y);
- show();
- }
- /***
- * 设置窗口显示
- *
- * @param x
- * @param y
- * @param dialog_x
- * @param dialog_y
- */
- public void windowDeploy(int dialog_width, int dialog_height, int dialog_x,
- int dialog_y) {
- window.setBackgroundDrawableResource(android.R.color.transparent); // 设置对话框背景为透明
- WindowManager.LayoutParams wl = window.getAttributes();
- wl.width = dialog_width;
- wl.height = dialog_height;
- // wl.alpha = 0.8f;
- wl.gravity = Gravity.LEFT | Gravity.TOP; // 不设置的话默认是居中
- wl.x = dialog_x - dialog_width / 2; // 要显示的位置x坐标
- wl.y = dialog_y;
- window.setAttributes(wl);
- window.setWindowAnimations(R.style.dialogWindowAnim); // 设置窗口弹出动画
- setCanceledOnTouchOutside(true);
- }
- }
我们只需要在activity中调用即可:
代码片段:
- textView.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- int x_begin = textView.getLeft();
- int x_end = textView.getRight();
- int y_begin = textView.getTop();
- int y_end = textView.getBottom();// 这个是要显示位置的纵坐标
- // 获取最中间的x坐标
- int x = (x_begin + x_end) / 2;// 这个值也就是屏幕最中间的值,也可以下面这样
- // int x=getWindowManager().getDefaultDisplay().getWidth()/2;
- // int[] location = new int[2];
- // textView.getLocationInWindow(location); // 获取在当前窗口内的绝对坐标
- // textView.getLocationOnScreen(location);// 获取在整个屏幕内的绝对坐标
- myDialog = new MyDialog(DialogDemoActivity.this,
- R.layout.dialog, x, y_end, title);
- View view = LayoutInflater.from(DialogDemoActivity.this)
- .inflate(R.layout.dialog, null);
- listView = (ListView) myDialog.getWindow().findViewById(
- R.id.lv_dialog);
- listView.setAdapter(new ArrayAdapter<String>(
- DialogDemoActivity.this, R.layout.text, R.id.tv_text,
- title));
- listView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1,
- int arg2, long arg3) {
- textView.setText(title[arg2]);
- myDialog.cancel();
- myDialog = null;
- }
- });
- }
- });
实现效果如下:

点击前 点击后 选择 选择后
实现起来也不难,有点要说明一下,这里我们用到了.9.png图片,这个图片会自动根据需要伸展,(重要的是不失真,这点很棒吧,详细介绍请点击连接).
android dialog 模拟新浪、腾讯title弹框效果的更多相关文章
- 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 ...
- 整合 新浪 腾讯 人人 qq空间 分享地址
function snsShare(snsId, title, content, image, url) { var snsUrl; // 新浪 腾讯 要申请appkey switch (snsId) ...
- android WebView将新浪天气为我所用 ------>仅供娱乐
新浪天气提供了一个网页 http://w.sina.com 浏览器访问: 这效果还可以了哦,直接用webview加载出来,效果也可以了哦,不过,这不是我要的.我不希望在我写的应用里到处铺满si ...
- Java 模拟新浪登录 2016
想学习一下网络爬虫.涉及到模拟登录,查阅了一番资料以后发现大部分都有点过时了,就使用前辈们给的经验,Firefox抓包调试,採用httpclient模拟了一下新浪登录. 不正确之处多多包括.须要的能够 ...
- jquery实现隐藏显示层动画效果、仿新浪字符动态输入、tab效果
已经有两年多没登陆csdn账号了,中间做了些旁的事,可是现在却还是回归程序,但改做前端了,虽然很多东西都已忘得差不多了,但还是应该摆正心态,慢慢来,在前端漫游,做一只快乐双鱼. 路是一步一步走出来的, ...
- 【多端应用开发系列1.1.1 —— Android:使用新浪API V2】服务器Json数据处理——Json数据概述
[前白] 一些基础的东西本系列中就不再详述了,争取尽量写些必不可少的技术要点. 由于本系列把Web Service 构建放到了第二部分,Android项目就采用新浪微博API v2作为服务器端. [原 ...
- 类似新浪 腾讯微博字数统计 控制js(区分中英文 符号)
<script> ; function Q(s) { return document.getElementById(s); } function checkWord(c) { len = ...
- HBuilder webApp开发(七)微信/QQ/新浪/腾讯微博分享
链接 https://blog.csdn.net/zhuming3834/article/details/51706256
- 接入新浪、腾讯微博和人人网的Android客户端实例 接入新浪、腾讯微博和人人网的Android客户端实例
做了个Android项目,需要接入新浪微博,实现时也顺带着研究了下腾讯微博和人人网的Android客户端接入,本文就跟大家分享下三者的Android客户端接入方法. 一.实例概述 说白了,接入微博就是 ...
随机推荐
- Office2010 pro附+激活工具
office2003经典的办公,office2010,很不错的办公工具配合Win7,就绝配! office2010,我也近几天接手她,慢慢熟悉... 00安装: 01激活: 内含office2010安 ...
- 传智168期JavaEE就业班 day03-js
* 课程回顾: * CSS * CSS的简介 * 层叠样式表. * CSS与HTML的结合(4种) * HTML的标签提供了属性 style="CSS的代码" * HTML提供了标 ...
- poj3580 伸展树(区间翻转 区间搬移 删除结点 加入结点 成段更新)
好题.我做了很久,学了大牛们的区间搬移.主要的代码都有注释. #include<cstdio> #include<cstring> #include<iostream&g ...
- 图解Android - System Service 概论 和 Android GUI 系统
通过 图解Android - Binder 和 Service 一文中,我们已经分析了Binder 和 Service的工作原理.接下来,我们来简要分析Android 系统里面都有哪些重要的Servi ...
- BZOJ-1876 SuperGCD Python(欧几里德算法)
第一次感觉Python艹题的快感 1876: [SDOI2009]SuperGCD Time Limit: 4 Sec Memory Limit: 64 MB Submit: 2461 Solved: ...
- codeforces 375D:Tree and Queries
Description You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...
- Sublime Text 3 笔记
Nearly all of the interesting files for users live under the data directory. The data directory is ~ ...
- IOC 构造函数注入vs属性注入
1.不管是构造函数注入还是属性注入,都要先把对象给new 出来,构造函数应该也是public.2.一般使用 配置文件,属性注入,不用使用特性,直接配置,初始化或依赖,凡是注入的,都要有访问权限,pub ...
- redis安装步骤
7.1创建业务安装用户 安装和配置Redis软件时,需要使用redis用户登录服务器进行相关操作,因此需要创建redis的业务安装用户组和redis的业务安装用户.此操作在主备机上同时进行. 创建用户 ...
- abstract 类 构造函数
public abstract class CommonReq { private String TransNo { get; set; } public String SubmitData { ge ...