首页 > 代码库 > Android -- PopupWindow的隐藏

Android -- PopupWindow的隐藏

PopupWindow的隐藏                                                                  

final PopupWindow window = mPageStatWin;if(null != window && window.isShowing()) {    win.dismiss();}

PopupWindow的显示及位置设置                                                     

window.showAtLocation(parent, Gravity.RIGHT | Gravity.BOTTOM, 10,10);

第一个参数指定PopupWindow的锚点view,即依附在哪个view上。
第二个参数指定起始点为parent的右下角,第三个参数设置以parent的右下角为原点,向左、上各偏移10像素。

//将PopupWindow作为anchor的下拉窗口显示。即在anchor的左下角显示window.showAsDropDown(anchor);//xoff,yoff基于anchor的左下角进行偏移。window.showAsDropDown(anchor, xoff, yoff);

如果没有充足的空间显示PopupWindow,那么PopupWindow的左下角将位于anchor的左上角来显示。

创建PopouWindow及相关参数设置                                                   

//创建一个包含自定义view的PopupWindowprivate PopupWindow makePopupWindow(Context cx) {    PopupWindow window;    window = new PopupWindow(cx);    TextView contentView = new TextView(cx);    contentView.setGravity(Gravity.CENTER);    final Resources res = cx.getResources();    // contentView.setBackgroundColor(R.color.page_window_bgcolor);    // window.setBackgroundDrawable(new    // ColorDrawable(res.getColor(R.color.page_window_bgcolor)));    contentView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,            LayoutParams.WRAP_CONTENT));    //设置PopupWindow显示和隐藏时的动画    window.setAnimationStyle(R.style.AnimationFade);    //设置PopupWindow的大小(宽度和高度)    window.setWidth(res.getDimensionPixelSize(R.dimen.page_window_width));    window.setHeight(res.getDimensionPixelSize(R.dimen.page_window_height));    //设置PopupWindow的内容view    window.setContentView(contentView);        //设置PopupWindow外部区域是否可触摸        window.setOutsideTouchable(true);    return window;}

PopupWindow显示和隐藏的动画设置                                                

<!-- PopupWindow窗口淡入淡出动画 --><style name="AnimationFade">    <item name="android:windowEnterAnimation">@anim/fade_in</item>    <item name="android:windowExitAnimation">@anim/fade_out</item></style>
window.setAnimationStyle(R.style.AnimationFade);

PopupWindow的焦点设置                                                             

window.setFocusable(true); //设置PopupWindow可获得焦点window.setTouchable(true); //设置PopupWindow可触摸window.setOutsideTouchable(true); //设置非PopupWindow区域可触摸

PopupWindow的显示及显示位置设置                                                

window.showAtLocation();window.showAsDropDown();

我是天王盖地虎的分割线                                                             

 

 

参考:http://orgcent.com/android-popupwindow-usage/

Android -- PopupWindow的隐藏