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. scrapy中运行爬虫时出现twisted critical unhandled error错误

    1. 试试这条命令: twisted critical unhandled error on scrapy tutorial python python27\scripts\pywin32_posti ...

  2. (7) 引用Objective-C class library

    原文 引用Objective-C class library 这个范例是如何在Xamarin.ios中去使用一个我们自行在Xcode中开发的Objective-c Class Library. 主要会 ...

  3. jQuery.fn和jQuery.prototype jquery.extend() jquery.fn.extend()区别介绍

    这里的 jQuery , jQuery.fn , jQuery,fn,init ,jQuery,prototype 都代表什么. 来看下jQuery的源码是怎么样定义的: (function( win ...

  4. C语言入门(6)——C语言常用数学函数

    在编码过程中会经遇到数学运算,幸运的是C语言提供了非常丰富的数学函数库. 在数学中使用函数有时候书写可以省略括号,而C语言要求一定要加上括号,例如sin(pi/2)这种形式.在C语言的术语中,pi/2 ...

  5. C,C++经典(程序、错误程序)

    1,程序 未执行完错误的return 0

  6. 【Linux学习】Ubuntu下嵌入式交叉编译环境arm-linux-gcc搭建

    (1)首先选择一个路径用来存放arm-linux-gcc.我选用的是/home/book,并在以下建立一个目录arm-linux-gcc. (2)利用cp EABI-4.3.3_Emdedsky_20 ...

  7. 根据输出设置select的被选中值

    $("#startupStatus").find("option").map(function(i) { if ($('#st-status').val() = ...

  8. 网络基本功(二十七):Wireshark抓包实例分析HTTP问题

    转载请在文首保留原文出处:EMC中文支持论坛https://community.emc.com/go/chinese 介绍 HTTP的问题可能是由于慢速服务器或客户端,TCP性能问题,本文讨论上述问题 ...

  9. MMDrawerController 的实践,已经实现,几行简单的代码实现侧栏

    学习方法,看readme,看给的Demo 看功能怎么实现的去模仿,个人感觉模仿是最快的学习方法 废话少说,上代码 导入MMDrawerController框架我就不多少了,之后做什么才是我们才关注的事 ...

  10. AOP 切面编程

    简介 如果你很熟悉面向方面编程(AOP),你就会知道给代码增加“切面”可以使代码更清晰并且具有可维护性.但是AOP通常都依赖于第三方类库或者硬编码的.net特性来工作.虽然这些实现方式的好处大于它们的 ...