android PopUp window的使用
来源:互联网 发布:与制造业相关的数据 编辑:程序博客网 时间:2024/04/29 21:24
Android的popupWindow类似一个不能动的widget,它显示在别的View之上。
具体操作如下:
主View:
/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@color/background"
>
</LinearLayout>
要显示在PopupWindow上的View:
<?xml version="1.0" encoding="utf-8"?>
/layout/extra.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<ImageButton android:id="@+id/cancel" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="top|right"
android:src="@drawable/del" android:layout_marginTop="10dip"
android:layout_marginRight="10dip" android:layout_marginBottom="10dip"
android:background="#0000003D"/>
<ScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:text="欢迎使用AudioPlayer!\n\n
android:textColor="#99FFFFFF"
android:autoLink="email|web"/>
</ScrollView>
</LinearLayout>
代码实现:
View extralView = getLayoutInflater().Inflater(R.layout.extra, null);
PopupWindow extral = new PopupWindow(extralView);
接下来就是如何将这个extral触发显示出来,通常是用Button触发,但是也可以通过别的方式:
在onCreate中加入
Looper.myQueue().addIdleHandler(new IdleHandler() {
public boolean queueIdle() {
// TODO Auto-generated method stub
if (extraWindow != null) {
extraWindow.showAtLocation(findViewById(R.id.main), Gravity.TOP,0, 0);
extraWindow.update(0, 25, ScreenWidth, 60);
}
return false;
}
});
ScreenWidth可以通过Diaplay得到。
在这里的IdleHandler是在后台处理消息的一种方式,当目前用户没有操作时触发。一般,当我们不需要人为触发时可以通过这种方式触发。
- android PopUp window的使用
- Popup Window 使用
- 【Android】Popup Window 在 Android Activity无法弹出的问题
- ArcGIS for Android 获取webmap的popup window(DynamicMapServiceLayer)
- ArcGIS for Android 获取webmap的popup window(FeatureLayer)
- 实现半透明的popup window
- window.popup
- Popup Window
- Android 防止popup window遮挡软键盘
- WPF Popup的使用
- popup window不能自动关闭的问题
- iOS: popup半透明的modal window
- Dialog 和 Popup Window 的区别
- Android Menu:使用Popup Menu
- Android Popup Menu的使用方法
- wpf中popup的使用
- PopUp和Graphics的使用
- Popup Window when keydown
- 使用Shiro1.2中的PasswordService实现密码加密存储和比对
- android4.0 输入法框架分析
- 一些技术文档
- STL的使用
- python post文件
- android PopUp window的使用
- 10家不错的iphone编程资源站
- 在Amazon EC2实例上安装配置rails3+nginx运行环境
- 如何做一个优秀的领导者
- Java I/O流-总结(InputStream,OutputStream,Reader,Writer)
- 程序员求职之道(《程序员面试笔试宝典》)
- Oracle,SQl,MySql实现分页查询
- JavaFX 皮肤功能
- C++标准转换运算符dynamic_cast