高速公路合肥中标单位:弹出小窗口,PopupWindow的使用
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 19:13:51
弹出小窗口,PopupWindow的使用
在程序里弹出一个小窗口,像系统的MediaController一样,具体做法:先在mail.xml的layout布局里加一个id,这个到后面会用到的,
1
23 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
23 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 android:gravity="center"
7 android:background="#00000000"
8 >
910 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 >
1718 android:id="@+id/sounddown"
19 android:layout_width="wrap_content"
20 android:layout_height="wrap_content"
21 android:src="@drawable/sounddown"
22 />
23
2425 android:id="@+id/textNow"
26 android:layout_width="wrap_content"
27 android:layout_height="wrap_content"
28 android:textSize="20sp"
29 android:text=" "
30 />
3132 android:id="@+id/seekbar"
33 android:layout_width="500dip"
34 android:layout_height="wrap_content"
35 android:max="10000"
36 />
3738 android:id="@+id/textAll"
39 android:layout_width="wrap_content"
40 android:layout_height="wrap_content"
41 android:textSize="20sp"
42 android:text=" "
43 />
4445 android:id="@+id/soundup"
46 android:layout_width="wrap_content"
47 android:layout_height="wrap_content"
48 android:src="@drawable/soundup"
49 />
50
5152 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
60
61
最后就是java文件,
1 public class MainActivity extends Activity {如果要响应PopupWindow里的widget,可以用LayoutInflater过滤xml文件,再用View view=getLayoutInflater().inflate(resource, root);就可以了。
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的使用
电脑IE使用过程弹出错误故障窗口的解决办法
自适应图片大小的弹出窗口
jQuery的弹出窗口 ColorBox
弹出窗口代码
Internet Explorer弹出莫名窗口的应对方法
解析windows 7的UAC频繁弹出询问窗口
PopupWindow
如何在运行 Windows XP Service Pack 2 的计算机上配置弹出窗口阻止程序
关闭弹出窗口简易一法1
aspx页面弹出窗口代码大全
弹出窗口函数MessageBox用法、分析及相应源代码
一劳永逸 让你与IE弹出窗口彻底告别
Word2003时弹出这个“无法访问您试图使用功能所在的网络位置”输入包含安装...
印堂——反映五脏健康状况的小窗口
违规弹出窗口最高罚10万 3Q大战各方均欢迎新规
工信部拟规定在用户终端违规弹出窗口可罚10万
第五讲 如何在网页中制作弹出窗口和播放音视频文件2
第五讲 如何在网页中制作弹出窗口和播放音视频文件222
改变电脑窗口背景颜色,适用于长时间使用电脑的办公室人员
健康使用电脑——使浏览器的窗口和桌面变成绿色
数码相机使用的小窍门
手机使用的小技巧
移动硬盘的使用小建议