本文實(shí)例講述了Android popupWindow彈出窗體實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
1. 建立popupwindow顯示的布局頁(yè)面(普通的view任意布局)
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="80dip" android:background="@drawable/popup_yellow_window_bg" android:orientation="horizontal" > <TextView android:id="@+id/popupwindow_app_uninstall_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:drawableTop="@drawable/kn_malware_scan_deep_click" android:text="卸 載"/></LinearLayout>
2. activity中布局加載以及填充,建立popupwindow對(duì)象,設(shè)置相應(yīng)參數(shù)或?qū)傩?/p>
View contentView = View.inflate(getApplicationContext(), R.layout.popup_window, null);LinearLayout ll_uninstall = (LinearLayout) contentView.findViewById(R.id.ll_uninstall);//設(shè)置popupwindow內(nèi)布局組件的監(jiān)聽(與其他組件相似)MyOnClickListener l = new MyOnClickListener(position);ll_uninstall.setOnClickListener(l);PopupWindow mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, 70);int[] arrayOfInt = new int[2];view.getLocationInWindow(arrayOfInt);int x = arrayOfInt[0] + 60;int y = arrayOfInt[1];//1 指定popupwindow的背景 2 popupwindow能夠獲得焦點(diǎn)mPopupWindow.setBackgroundDrawable(new BitmapDrawable());mPopupWindow.setFocusable(true);mPopupWindow.showAtLocation(view, Gravity.LEFT|Gravity.TOP, x, y);//在合適位置取消popupwindow顯示mPopupWindow.dismiss();
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注