Android UI开发第三篇——popupwindow
来源:互联网 发布:c语言代码图片壁纸 编辑:程序博客网 时间:2024/06/05 13:09
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;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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();}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (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() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubpop.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>
/**
* @author 张兴业
* http://blog.csdn.net/xyz_lmn
* 我的新浪微博:@张兴业TBOW
*/
- Android UI开发第三篇——popupwindow
- Android UI开发第三篇——popupwindow
- Android UI开发第三篇——popupwindow
- Android UI开发第三篇-PopupWindow
- Android UI开发第三十四篇——SlidingPaneLayout
- android开发——popupwindow
- Android UI开发第三十三篇——Navigation Drawer For Android API 7
- Android UI编程(3)——Popupwindow对话框
- Android UI开发第三十二篇——Creating a Navigation Drawer
- Android UI开发第三十五篇——AppCompat实现Action Bar
- Android UI开发第三十六篇——使用Volley加载图片列表
- Android UI开发第三十九篇——Tab界面实现汇总及比较
- Android UI开发第三十六篇——使用Volley加载图片列表
- Android UI开发第三十五篇——AppCompat实现Action Bar
- Android UI开发第三十五篇——AppCompat实现Action Bar
- Android UI开发第三十六篇——使用Volley加载图片列表
- Android UI设计:PopupWindow
- android UI(1)-PopupWindow
- 开站第一篇
- C#中"@"符号的用法
- hadoop0.20.2下相关问题处理方法
- JS中window.showModalDialog()详解
- JPA注解 catalog
- Android UI开发第三篇——popupwindow
- 为什么我的网站打开那么慢?
- MDI 取得childFrame子框架的menu菜单
- 利用silverlight的导航控件,实现翻页效果
- 初学openCV 之从文件中读入一幅图像,将之反色并显示
- ubuntu11.10,checking battery state
- Oracle - Lead() over (partition by xxx order by xxx )
- 前端优化之图片优化自动化
- 技术行业也有砖家 -- 从一篇IT新闻引发的思考