Android中文API——PopupWindow

來源:互聯網
上載者:User

標籤:android   api   popuwindow   

此文上半部分為本人翻譯API文檔,下半部分轉自網友分享資料。

API文檔

繼承樹
java.lang.Object
? android.widget.PopupWindow

  • 概述:
    popupWindow,顧名思義,用作在當前Activity前彈出一個介面,這個介面可以用來展示任何類型的View。

  • 公用的構造器

PopupWindow() PopupWindow(Context context) PopupWindow(Context context, AttributeSet attrs) PopupWindow(Context context, AttributeSet attrs, int defStyle) PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) //以上幾種構造方法都是建立一個空的、沒有擷取焦點的、長寬尺寸均為0的popup window。//(使用較少)
PopupWindow(View contentView, int width, int height) //建立一個沒有擷取焦點、長為width、寬為height,內容為contentView的popup window.PopupWindow(View contentView, int width, int height, boolean focusable) //類似上面那個,但第四個參數可以控制是否擷取焦點//(這2種使用較多)!!!!
  • 公用方法
void  dismiss() //使popup window消失int  getAnimationStyle() //返回該popup window出現或消失的動畫類型,傳回值為整型Drawable  getBackground() //返回popup window的背景,傳回值為Drawable類型void  setContentView(View contentView) //設定該popup window顯示的內容View  getContentView() //返回popup window展示的內容,傳回值為一個Viewint  getHeight() //返回該popup window的高度值,傳回值為int型void  setFocusable(boolean focusable) //設定該popup window是否獲得焦點void  setInputMethodMode(int mode) /*設定IME的模式,參數為這三個:INPUT_METHOD_FROM_FOCUSABLE(根據是否可以獲得焦點決定), INPUT_METHOD_NEEDED(允許IME), or INPUT_METHOD_NOT_NEEDED(不允許IME)。當popup window中包含EditText時可能會涉及這方面,可能是出現IME顯示在popup window後面,導致無法輸入的問題,可以修改焦點和這裡。*/int  getInputMethodMode() //返回當前popup window對IME的設定模式int  getMaxAvailableHeight(View anchor) //返回能使當前popup window完整顯示的最大高度int  getMaxAvailableHeight(View anchor, int yOffset) //同上void  setSoftInputMode(int mode) //設定IME的操作模式int  getSoftInputMode() //獲得IME的操作模式int  getWidth() Return this popup‘s width MeasureSpecvoid  setHeight(int height) Change the popup‘s height MeasureSpecboolean  isAboveAnchor() //判斷popup window是否超出了父View的布局之外boolean  isFocusable() //判斷當前popup window是否獲得焦點boolean  isOutsideTouchable() //判斷當前pw的外界觸碰是否有響應boolean  isShowing() //判斷當前popup window是否處於顯示狀態boolean  isSplitTouchEnabled() //判斷當前pw是否支援多點觸碰boolean  isTouchable() //判斷當前pw是否接受觸摸事件void  setAnimationStyle(int animationStyle) //設定popup window的動畫樣式,有什麼樣式去Animationvoid  setBackgroundDrawable(Drawable background)//設定pw背景void  setClippingEnabled(boolean enabled) /*允許快顯視窗超出螢幕範圍。預設情況下,視窗被夾到螢幕邊界。設定為false將允許Windows精確定位。也就是說,如果這個Popupwindow顯示地區 不足或者層疊將導致繪製位置計算不準確,需要手動設定為false */boolean  isClippingEnabled() Indicates whether clipping of the popup window is enabled.void  setIgnoreCheekPress() /*這個以前我也沒見過,還蠻好玩。設定是否忽略“臉頰觸碰”,預設為false,即不忽略。什麼是“臉頰觸碰”? Events都有一個大小,當Events的大小比手指尺寸大時即為CheekPress,這個可能常用於打電話時臉頰碰到螢幕的情況*/void  setOnDismissListener(PopupWindow.OnDismissListener onDismissListener) //popup window消失時的回調方法void  setOutsideTouchable(boolean touchable) /*控制popup window以外的地區被點擊後是否有影響,一般與setTouchInterceptor配合使用*/void  setSplitTouchEnabled(boolean enabled) //是否允許分開、多點觸控,一般很少用,不容易控制void  setTouchInterceptor(View.OnTouchListener l) /*當popup window被觸碰時的回調方法*/void  setTouchable(boolean touchable) //設定popup window是否可觸碰void  setWidth(int width) /*修改popup window的寬度,如果已經顯示了popup window,修改後不會立即更新。只有下次出現或者調用update()方法才會更新*/void  setWindowLayoutMode(int widthSpec, int heightSpec) //改變popup管理的window的尺寸void  showAsDropDown(View anchor) /*(anchor,顧名思義:錨。)以觸發彈出窗的anchor為基準,出現在anchor的正下方,彈出的pop_view左上方正對view的左下角,位移量預設為0,0*/void  showAsDropDown(View anchor, int xoff, int yoff)/* 有參數的話,就是以anchor的左下角進行位移,xoff正的向右,負的向左. yoff,正的向下,負的向上*/ void  showAsDropDown(View anchor, int xoff, int yoff, int gravity)/*和上一種相似,這個用的比較少*/void  showAtLocation(View parent, int gravity, int x, int y) /*在特定的地點彈出一個window顯示指定的內容parent:傳你當前Layout的id;  gravity:Gravity.BOTTOM(以螢幕左下角為參照),位移量會以它為基準點 當x y為0,0是出現在底部置中*/void  update(View anchor, int width, int height)  void  update(int x, int y, int width, int height) void  update(View anchor, int xoff, int yoff, int width, int height) Updates the position and the dimension of the popup window.void  update() void  update(int x, int y, int width, int height, boolean force) void  update(int width, int height) /*都是更新popup window的尺寸和位置,取決於你是在參數裡進行改變,還是調用setWidth等方法改變後再更新*/
Android PopupWindow的使用和分析

Android中文API——PopupWindow

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.