Android UI开发第三篇-PopupWindow
来源:互联网 发布:超级优化还原 编辑:程序博客网 时间:2024/06/11 05:19
PopupWindow在android.widget包下,弹出窗口的形式展示。官方文档对该控件的描述是:“一个弹出窗口控件,可以用来显示任意视图(View),而且会浮动在当前 活动(activity)的顶部”。PopupWindow可以让我们实现多种自定义控件,例如:menu、alertdialog等弹窗似的View。
Popupwindow需要在onCreate时初始化、通过触发事件展示出来。
- public class ShowPopupWindow extends Activity implements View.OnClickListener {
- View view;
- PopupWindow pop;
- Button btnShowAsDrawDown;
- Button btnShowAsDrawDown1;
- Button btnShowAtLocation;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.popup_activity);
- btnShowAsDrawDown = (Button) findViewById(R.id.btnShowAsDrawDown);
- btnShowAsDrawDown.setOnClickListener(this);
- btnShowAsDrawDown1 = (Button) findViewById(R.id.btnShowAsDrawDown1);
- btnShowAsDrawDown1.setOnClickListener(this);
- btnShowAtLocation = (Button) findViewById(R.id.btnShowAt);
- btnShowAtLocation.setOnClickListener(this);
- initPopupWindow();
- }
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- switch (v.getId()) {
- case R.id.btnShowAsDrawDown:
- if (pop.isShowing()) {
- pop.dismiss();
- } else {
- pop.showAsDropDown(v);
- }
- break;
- case R.id.btnShowAsDrawDown1:
- if (pop.isShowing()) {
- pop.dismiss();
- } else {
- pop.showAsDropDown(v, 0, -160);
- }
- break;
- default:
- if (pop.isShowing()) {
- pop.dismiss();
- } else {
- pop.showAtLocation(findViewById(R.id.main),
- Gravity.CENTER_HORIZONTAL, 0, 0);
- }
- break;
- }
- }
- private void initPopupWindow() {
- view = this.getLayoutInflater().inflate(R.layout.popup_window, null);
- pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- pop.setOutsideTouchable(true);
- view.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- pop.dismiss();
- }
- });
- }
- }
popup_activity.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/main"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="pop demo!" />
- <Button
- android:id="@+id/btnShowAsDrawDown"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Show as drawndown(one parameter)" />
- <Button
- android:id="@+id/btnShowAsDrawDown1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Show as drawndown(three parameters)" />
- <Button
- android:id="@+id/btnShowAt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Show At Location" />
- </LinearLayout>
popup_window.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#d3d3d3"
- android:gravity="center_horizontal"
- android:orientation="vertical" >
- <Button
- android:id="@+id/btn_pop"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dip"
- android:text="Close" />
- </LinearLayout>
0 0
- Android UI开发第三篇-PopupWindow
- Android UI开发第三篇——popupwindow
- Android UI开发第三篇——popupwindow
- Android UI开发第三篇——popupwindow
- Android UI设计:PopupWindow
- android UI(1)-PopupWindow
- Android UI 之 PopupWindow
- Android UI开发第三十四篇——SlidingPaneLayout
- Android开发 第三方免费UI组件
- Android UI:PopupWindow基本学习
- Android UI PopupWindow 简单使用
- Android第三方开源库:PopupWindow相关
- Android开发之PopupWindow
- Android开发之PopupWindow
- Android开发之PopupWindow
- Android开发之PopupWindow
- Android开发之PopupWindow
- Android开发自定义popupwindow
- 【bzoj2953】【poi2002】【商务旅行】【树上倍增】
- 第8周实践项目2-建立链串的算法库
- 远程连接服务器无法拷贝本地文件解决(远程桌面无法复制文件)
- IOS--- Segue区别及视图的切换
- Android 双向滑动菜单完全解析
- Android UI开发第三篇-PopupWindow
- react native 环境搭建(iOS)
- 优先级反转问题的和解决方法
- 第9周—项目2 对称矩阵压缩存储的实现与应用(1)用压缩形式存储对称矩阵
- int 转 string
- 基本常用的正则表达式
- fl2440添加内核usb驱动时的问题
- 采用dlopen、dlsym、dlclose加载动态链接库【总结】
- Could not obtain transaction-synchronized Session for current thread