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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.jj.popupwindow;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow; /***
* PopupWindow
*
* @author zhangjia
*
*/
public class MainActivity extends Activity {
private Button button;
private PopupWindow popupWindow;
private LinearLayout layout;
private ListView listView;
private String title[] = { "全部", "我的微博", "周边", "智能排版", "同学" }; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.tv_title);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button.getTop();
int y = button.getBottom() * 3 / 2;
int x = getWindowManager().getDefaultDisplay().getWidth() / 4; showPopupWindow(x, y);
}
});
} public void showPopupWindow(int x, int y) {
layout = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(
R.layout.dialog, null);
listView = (ListView) layout.findViewById(R.id.lv_dialog);
listView.setAdapter(new ArrayAdapter<String>(MainActivity.this,
R.layout.text, R.id.tv_text, title)); popupWindow = new PopupWindow(MainActivity.this);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow
.setWidth(getWindowManager().getDefaultDisplay().getWidth() / 2);
popupWindow.setHeight(300);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setContentView(layout);
// showAsDropDown会把里面的view作为参照物,所以要那满屏幕parent
// popupWindow.showAsDropDown(findViewById(R.id.tv_title), x, 10);
popupWindow.showAtLocation(findViewById(R.id.main), Gravity.LEFT
| Gravity.TOP, x, y);//需要指定Gravity,默认情况是center. listView.setOnItemClickListener(new OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
button.setText(title[arg2]);
popupWindow.dismiss();
popupWindow = null;
}
});
} }

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

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

    http://blog.csdn.net/jj120522/article/details/7764183 首先我们看一下新浪微博的效果(其它就是一个dialog):                点 ...

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

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

  3. JS遮罩层弹框效果

    对于前端开发者来说,js是不可缺少的语言.现在我开始把我日常积累的一些js效果或者通过搜索自己总结的一些效果分享给大家,希望能够帮助大家一起进步,也希望大家能够多多支持! 1.今天我先分享一个遮罩层弹 ...

  4. Java 模拟新浪登录 2016

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

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

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

  6. onload + setTimeout 用法,制作广告弹框效果

    一般来说,只有 <body>,<img>, <link>, <script>,<frame>, <frameset>, < ...

  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. 仿糯米弹框效果demo

    代码例如以下: <!doctype html> <html lang="en"> <head> <meta charset="U ...

随机推荐

  1. 《离散数学之把妹要诀》的js实现

    网上看到一篇有意思的文章<离散数学之把妹要诀> 就用JS写了上面所讲的配对方式: 首先设定变量 // 男生理想列表 var menPreference = { A: [1, 2, 3, 4 ...

  2. function(ev) //括号里的ev是什么东西,什么意思?

    事件对象: 楼上的不要误导新人 ev是我们获取事件详细信息的event是IE的写法 大多数人是写window.event 其实区别也差不多 好像window.event更安全些 我也不记得了 火狐呢 ...

  3. 读取本地HTML的小说阅读器应用源码项目

    该源码是一个不错的读取本地HTML的小说阅读器,读取本地HTML的小说阅读器,并且源码也比较简单的,非常适合我们的新手朋友拿来学习,有兴趣的朋友研究下. 源码下载: http://code.662p. ...

  4. VHDL设计时参数定义的方法 例子

    -- SPtb LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; USE IEEE.STD_LOGIC_ ...

  5. Mocha 从0开始

    Mocha Mocha 是具有丰富特性的 JavaScript 测试框架,可以运行在 Node.js 和浏览器中,使得异步测试更简单更有趣.Mocha 可以持续运行测试,支持灵活又准确的报告,当映射到 ...

  6. 解密电子书之二:EPD控制芯片

    EPD控制芯片大致上相当于计算机的显卡,没了它,所有电子书都变白板.类似显卡中的ATI与NVIDIA,EPD控制芯片中也是两家:Surf(泰信科)和EPSON(爱普生),其中爱普生是最早推出电子纸显示 ...

  7. 深入分析MFC文档视图结构(项目实践)

    k_eckel:http://www.mscenter.edu.cn/blog/k_eckel 文档视图结构(Document/View Architecture)是MFC的精髓,也是Observer ...

  8. BZOJ 1179 [Apio2009]Atm(强连通分量)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1179 [题目大意] 给出一张有向带环点权图,给出一些终点,在路径中同一个点的点权只能累 ...

  9. lodash的中文文档(不全)

    http://dingliang-321.iteye.com/blog/2184747

  10. HTML系列(五):超链接

    <a> 标签定义超链接,最重要的属性是 href 属性,它指示链接的目标.通过将href属性设定不同类型的值可以使链接指向不同类型的链接地址:内部链接.外部链接.锚链接. 内部链接指的是同 ...