//为创建PopupWindow需要的View,
//enclsure_download是布局文件全名是enclsure_download.xml
//下面详细介绍enclsure_download.xml
View popupView = getLayoutInflater().inflate(R.layout.enclsure_download,null);
//构建出PopupWindow
mPopupWindow = new PopupWindow(popupView);
//PopupWindow的高
mPopupWindow.setHeight(300);
//PopupWindow的宽
mPopupWindow.setWidth(400);
//PopupWindow触摸
mPopupWindow.setTouchable(true);
//PopupWindow外触摸关闭
mPopupWindow.setOutsideTouchable(true);
//PopupWindow背景图片
mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),(Bitmap) null));
//PopupWindow显示开始位置
mPopupWindow.showAsDropDown(es_bt1);
//为PopupWindow上的组件绑定id
//注意的是popupView.findViewById(R.id.es_dl_open)要PopupWindow的view上findViewById();
es_dl_open =(Button)popupView.findViewById(R.id.es_dl_open); es_dl_pb = (ProgressBar) popupView.findViewById(R.id.es_dl_p); es_dl_tv=(TextView) popupView.findViewById(R.id.es_dl_ptv); es_dl_filename = (TextView) popupView.findViewById(R.id.es_dl_name); es_dl_delete = (ImageView) popupView.findViewById(R.id.es_dl_delete);
//布局文件enclsure_download.xml的代码如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bbutton_info"> <ImageButton android:id="@+id/es_dl_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/delete" android:layout_gravity="right" /> <TextView android:id="@+id/es_dl_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="没有文件" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <ProgressBar android:id="@+id/es_dl_p" android:layout_width="wrap_content" android:layout_height="4dp" style="?android:attr/progressBarStyleHorizontal" android:layout_weight="10"/> <TextView android:id="@+id/es_dl_ptv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="right" android:text="0%"/> </LinearLayout> <Button android:id="@+id/es_dl_open" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="right" android:background="@color/word_blue2" android:text="打开"/> </LinearLayout>