弹出小窗口,PopupWindow的使用
2012-03-29 15:44
489 查看
点击打开链接:/article/5534371.html
在程序里弹出一个小窗口,像系统的MediaController一样,具体做法:先在mail.xml的layout布局里加一个id,这个到后面会用到的,
复制代码
接着布局文件里写一个control.xml文件,里面放一些要显示的widget,
复制代码
最后就是java文件,
复制代码
如果要响应PopupWindow里的widget,可以用LayoutInflater过滤xml文件,再用View view=getLayoutInflater().inflate(resource, root);就可以了。
在程序里弹出一个小窗口,像系统的MediaController一样,具体做法:先在mail.xml的layout布局里加一个id,这个到后面会用到的,
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="fill_parent" 5 android:layout_height="fill_parent" 6 android:id="@+id/linear"<!--这个一定要加--> 7 >
复制代码
接着布局文件里写一个control.xml文件,里面放一些要显示的widget,
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="fill_parent" 5 android:layout_height="fill_parent" 6 android:gravity="center" 7 android:background="#00000000" 8 > 9 <LinearLayout 10 android:orientation="horizontal" 11 android:layout_width="fill_parent" 12 android:layout_height="wrap_content" 13 android:gravity="center_horizontal" 14 android:layout_marginTop="5dip" 15 android:layout_marginBottom="5dip" 16 > 17 <ImageButton 18 android:id="@+id/sounddown" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:src="@drawable/sounddown" 22 /> 23 24 <TextView 25 android:id="@+id/textNow" 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:textSize="20sp" 29 android:text=" " 30 /> 31 <SeekBar 32 android:id="@+id/seekbar" 33 android:layout_width="500dip" 34 android:layout_height="wrap_content" 35 android:max="10000" 36 /> 37 <TextView 38 android:id="@+id/textAll" 39 android:layout_width="wrap_content" 40 android:layout_height="wrap_content" 41 android:textSize="20sp" 42 android:text=" " 43 /> 44 <ImageButton 45 android:id="@+id/soundup" 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:src="@drawable/soundup" 49 /> 50 </LinearLayout> 51 <LinearLayout 52 android:orientation="horizontal" 53 android:layout_width="fill_parent" 54 android:layout_height="wrap_content" 55 android:gravity="center_horizontal" 56 android:background="#0000003D" 57 > 58 59 </LinearLayout> 60 61 </LinearLayout>
复制代码
最后就是java文件,
1 public class MainActivity extends Activity { 2 /** Called when the activity is first created. */ 3 private Button show; 4 public PopupWindow mPopupWindow; 5 private boolean boo=true; 6 @Override 7 public void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.main); 10 show = (Button) findViewById(R.id.button); 11 show.setOnClickListener(new Button.OnClickListener(){ 12 13 @Override 14 public void onClick(View v) { 15 // TODO Auto-generated method stub 16 if(boo){ 17 boo=false; 18 check(); 19 mPopupWindow.showAtLocation(findViewById(R.id.linear), Gravity.RIGHT|Gravity.BOTTOM, 0,0); 20 }else{ 21 boo=true; 22 mPopupWindow.dismiss(); 23 } 24 25 }}); 26 } 27 28 private void check(){ 29 if(mPopupWindow==null){ 30 mPopupWindow=new PopupWindow(getLayoutInflater().inflate(R.layout.controler, null),LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); 31 } 32 if(mPopupWindow.isShowing()){ 33 mPopupWindow.dismiss(); 34 } 35 } 36 }
复制代码
如果要响应PopupWindow里的widget,可以用LayoutInflater过滤xml文件,再用View view=getLayoutInflater().inflate(resource, root);就可以了。
相关文章推荐
- android中使用PopupWindow实现弹出窗口菜单
- 弹出小窗口,PopupWindow的使用
- android中使用PopupWindow实现弹出窗口菜单
- TextView使用SpannableString设置复合文本 + android弹出窗口的实现(PopupWindow)
- Android Popupwindow弹出窗口的简单使用方法
- Android开发技巧——使用PopupWindow实现弹出菜单
- Android 使用PopupWindow实现弹出更多的菜单
- 使用POST方式弹出窗口的两种方法
- android弹出窗口的实现(PopupWindow)
- Unity3D 使用NGUI制作简易弹出窗口声音控制器
- C#使用Xamarin开发可移植移动应用(5.进阶篇显示弹出窗口与通讯中心)附源码
- ASP.NET使用弹出窗口(对话框)的体会
- android 弹出窗口组件(PopupWindow)
- Window.ShowModalDialog使用手册 js弹出框 不同于open此弹出窗口不会被阻止
- 【android开发】使用PopupWindow实现页面点击顶部弹出下拉菜单
- Android中弹出菜单PopupWindow的使用
- 打开一个iframe,从iframe更改父窗口parent里面的内容,jquery弹出窗口插件fancybox的使用
- detailview按钮列 点击弹出窗口中使用datagrid
- JS使用showModalDialog弹出窗口获得弹出窗口设定的值
- Android PopupWindow的使用技巧 Android上自定义弹出窗口