- 浏览: 914799 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
itzhongyuan:
java Random类详解 -
david_je:
你好,我看到你在C里面回调JAVA里面的方法是在native里 ...
Android NDK开发(1)----- Java与C互相调用实例详解 -
fykyx521:
请求锁是在 oncreate 释放实在ondestroy?? ...
Android如何保持程序一直运行 -
aduo_vip:
不错,总结得好!
Android读取assets目录下的资源 -
f839903061:
给的网址很给力哦!
Android 4.0.1 源码下载,编译和运行
1. 定义布局 供PopupWindow使用 如:hello.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
<Button
android:id="@+id/helloButton"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
<Button
android:id="@+id/helloButton"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
</LinearLayout>
2. 通过LayoutInflater 得到hello.xml 的 View view
Java代码
view = this.getLayoutInflater().inflate(R.layout.hello, null);
view = this.getLayoutInflater().inflate(R.layout.hello, null);
3. 创建PopupWindow pop 使用上面布局文件view
Java代码
pop = new PopupWindow(view,500,200);
pop = new PopupWindow(view,500,200);
4. 弹出PopupWindow
* 定义布局文件:main.xml 包括一个Button
Java代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="pop demo!"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="to pop!"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="pop demo!"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="to pop!"
/>
</LinearLayout>
* 弹出:有2种方式:一个是下拉方式 一个是指定位置
- 下拉:
Java代码
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAsDropDown(v);
}
});
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAsDropDown(v);
}
});
- 指定位置:
Java代码
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 20, 20);
}
});
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 20, 20);
}
});
5. 取消
Java代码
view.findViewById(R.id.helloButton).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.dismiss();
}
});
view.findViewById(R.id.helloButton).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.dismiss();
}
});
6. 其他问题:
* 发现很多人对PopupWindow 里面包含ListView后 对具体哪个item被点击的获取有疑问 所以就顺便测试一下 发现和普通用法一样啊 没什么特别之处啊 现在把用法和大家分享分享
写道
因为ListView是展开显示的 会导致不美观 所以以Spinner为例
6.1. 定义包含Spinner 的布局文件 hello.xml
Java代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
</LinearLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="40dip"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
</LinearLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="40dip"/>
</LinearLayout>
6.2. 得到Spinner的实例:spinner
Java代码
spinner = (Spinner)view.findViewById(R.id.spinner);
spinner = (Spinner)view.findViewById(R.id.spinner);
6.3. 绑定Spinner与具体数据 本例以联系人为例
Java代码
public void specifySpinner(){
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,c,
new String[] {People.NAME},
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
public void specifySpinner(){
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,c,
new String[] {People.NAME},
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
写道
别忘了联系人访问权限:
<uses-permission android:name="android.permission.READ_CONTACTS" />
6.4. 具体item的获取:
Java代码
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> adapter,View v,
int pos, long id) {
updateTitle(pos);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> adapter,View v,
int pos, long id) {
updateTitle(pos);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
写道
updateTitle(int) 用来把位置在标题中显示
public void updateTitle(int i){
this.setTitle("HelloPop:"+i);
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
<Button
android:id="@+id/helloButton"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
<Button
android:id="@+id/helloButton"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>
</LinearLayout>
2. 通过LayoutInflater 得到hello.xml 的 View view
Java代码
view = this.getLayoutInflater().inflate(R.layout.hello, null);
view = this.getLayoutInflater().inflate(R.layout.hello, null);
3. 创建PopupWindow pop 使用上面布局文件view
Java代码
pop = new PopupWindow(view,500,200);
pop = new PopupWindow(view,500,200);
4. 弹出PopupWindow
* 定义布局文件:main.xml 包括一个Button
Java代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="pop demo!"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="to pop!"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="pop demo!"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="to pop!"
/>
</LinearLayout>
* 弹出:有2种方式:一个是下拉方式 一个是指定位置
- 下拉:
Java代码
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAsDropDown(v);
}
});
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAsDropDown(v);
}
});
- 指定位置:
Java代码
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 20, 20);
}
});
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 20, 20);
}
});
5. 取消
Java代码
view.findViewById(R.id.helloButton).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.dismiss();
}
});
view.findViewById(R.id.helloButton).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
pop.dismiss();
}
});
6. 其他问题:
* 发现很多人对PopupWindow 里面包含ListView后 对具体哪个item被点击的获取有疑问 所以就顺便测试一下 发现和普通用法一样啊 没什么特别之处啊 现在把用法和大家分享分享
写道
因为ListView是展开显示的 会导致不美观 所以以Spinner为例
6.1. 定义包含Spinner 的布局文件 hello.xml
Java代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
</LinearLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="40dip"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/robot" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloPop!"
/>
</LinearLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="40dip"/>
</LinearLayout>
6.2. 得到Spinner的实例:spinner
Java代码
spinner = (Spinner)view.findViewById(R.id.spinner);
spinner = (Spinner)view.findViewById(R.id.spinner);
6.3. 绑定Spinner与具体数据 本例以联系人为例
Java代码
public void specifySpinner(){
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,c,
new String[] {People.NAME},
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
public void specifySpinner(){
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,c,
new String[] {People.NAME},
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
写道
别忘了联系人访问权限:
<uses-permission android:name="android.permission.READ_CONTACTS" />
6.4. 具体item的获取:
Java代码
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> adapter,View v,
int pos, long id) {
updateTitle(pos);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> adapter,View v,
int pos, long id) {
updateTitle(pos);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
写道
updateTitle(int) 用来把位置在标题中显示
public void updateTitle(int i){
this.setTitle("HelloPop:"+i);
}
发表评论
-
Android使用binder访问service的方式
2013-08-23 09:42 15791. 我们先来看一个与本地service通信的例子。 pub ... -
android-Service和Thread的区别
2013-08-23 09:17 887servie是系统的组件,它由系统进程托管(servicema ... -
git介绍
2013-08-01 14:49 990git介绍 使用Git的第一件事就是设置你的名字和email ... -
cocos2d-x学习之自动内存管理和常见宏
2013-07-29 15:41 8931.自动内存管理 1)概述 C++语言默认是 ... -
cocos2dx中利用xcode 调用java中的函数
2013-07-29 11:36 24971. 先把cocos2dx根目录中的 /Users/zhaos ... -
cocos2dx(v2.x)与(v1.x)的一些常用函数区别讲解
2013-07-29 10:35 1084第一个改动: CCLayer初始化 自定义Layer,类名 ... -
xcode与eclipse整合cocos2dx
2013-07-29 10:32 1205文档xcode版本是 204 1. 在xcode中创建coc ... -
git提交代码
2013-07-23 16:00 10211. 在本地创建一个Git的工作空间,在里面创建一个工程(如H ... -
Android.mk的用法和基础
2013-07-19 14:11 4305一个Android.mk file用来向编译系统描述你的源代码 ... -
eclipse配置NDK-Builder命令
2013-07-18 11:02 10071. 2. -
eclipse配置javah命令
2013-07-18 10:48 19691.找到javah命令所在的目录 我的为 /usr/bi ... -
Android SDL2.0 编译
2013-07-17 13:40 19381,下载: wget http://www.libsdl.o ... -
IntelliJ Idea 常用快捷键列表
2013-05-27 10:19 0Alt+回车 导入包,自动修 ... -
android应用后台安装
2013-05-21 12:02 940android应用后台安装,静默安装的代码实现方法 http ... -
编译linux内核映像
2013-05-21 11:33 937a)准备交叉编译工具链 android代码树中有一个pr ... -
如何单独编译Android源代码中的模块
2013-05-21 11:29 964一. 首先在Android源代码 ... -
Ubuntu安装JDK6和JDK5
2013-05-19 19:04 980sudo apt-get install sun-java6- ... -
java_jni详解_01
2013-05-08 17:15 930java中的jni 例子HelloWorld 准备过程: 1 ... -
下载android源码 中断解决原因
2013-05-07 15:51 1289解决方法 1. 浏览器登录https://android.go ... -
mac下编译ffmpeg1.1.4
2013-05-07 14:55 1339经过一番网上搜索 与 无数次的编译 终于成功了 下面献上编译 ...
相关推荐
实现的功能有弹出的PopupWindow上有EditText能与软键盘并存不冲突,弹出PopupWindow的时候背景自动改变灰度为半透明黑色,消失后背景灰度复原,PopupWindow还能根据自己的实际需求制定自己想要的弹出动画,以及...
android popupwindow 底部灰色背景
PopupWindow之显示顶层对话框代码
android 封装一个通用PopupWindow,避免重复造轮子,简化代码,方便管理。
仿微信右上角弹出PopupWindow的Demo,
Android源码——PopupWindow实现弹出菜单.zip
Android从屏幕底部滑动弹出PopupWindow,有动画效果,类似于sharesdk的分享页面滑动弹出效果。
popupwindow弹窗实现点击按钮,下方弹出popwindow,并且只是按钮下方有阴影,按钮以及上方没有阴影
让popupwindow显示在view的上方并与该view水平居中对齐
popupwindow 遮罩 窗帘式 从上往下 半显示 带动画 漂亮
和大家分享一下用一个PopupWindow来做一个指引蒙板的效果。鉴于网上对于“指引蒙板”的实现例子不是太多(或者是我找不到更多的),而且好像有很多的例子都是用一个Frame布局+Fragment去完成,对于这种做法自己不太...
AS写的PopupWindow demo blog:http://blog.csdn.net/shenyuanqing/article/details/48136639
点击按钮在屏幕下方会出现PopupWindow,PopupWindow中的PickerView可以用来选择时间。
Android PopupWindow与Activity之间的数据传递