android-PopupWindow快顯視窗 - 隨心

來源:互聯網
上載者:User

Android的對話方塊有兩種:PopupWindow和AlertDialog。它們的不同點在於:
AlertDialog的位置固定,而PopupWindow的位置可以隨意
AlertDialog是非阻塞線程的,而PopupWindow是阻塞線程的
PopupWindow的位置按照有無位移分,可以分為位移和無位移兩種;按照參照物的不同,可以分為相對於某個控制項(Anchor錨)和相對於父控制項。具體如下
showAsDropDown(View anchor):相對某個控制項的位置(正左下方),無位移
showAsDropDown(View anchor, int xoff, int yoff):相對某個控制項的位置,有位移
showAtLocation(View parent, int gravity, int x, int y):相對於父控制項的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以設定位移或無位移
不解釋之際上代碼

[java] 
LayoutInflater inflater = (LayoutInflater) DeliveryActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.popup_sms, null); 
 
LinearLayout popup_contact = (LinearLayout)view.findViewById(R.id.popup_contact); 
LinearLayout popup_input = (LinearLayout)view.findViewById(R.id.popup_input); 
popup_contact.setOnClickListener(DeliveryActivity.this); 
popup_input.setOnClickListener(DeliveryActivity.this); 
 
selectSMSPopup = new PopupWindow(view); 
selectSMSPopup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); 
selectSMSPopup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); 
// 必須設定,否則獲得焦點後頁面上其他地方點擊無響應 
selectSMSPopup.setBackgroundDrawable(new BitmapDrawable()); 
// 設定焦點,必須設定,否則listView無法響應 
selectSMSPopup.setFocusable(true); 
// 設定點擊其他地方 popupWindow消失 
selectSMSPopup.setOutsideTouchable(true); 
// 顯示在某個位置 
selectSMSPopup.showAsDropDown(LinearLayout

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.