本文实例为大家分享了android popupwindow的用法,供大家参考,具体内容如下
<强>一,基本用法强>
一般做法,新建类继承popupwindow。例
/* * * popupwindow基本用法 *由管理员> 公共空间showAsDropDown(查看锚、int发送葡开int yoff) { 如果(isShowing () | | mContentView==null) { 返回; } registerForScrollChanged(锚,发送葡开,yoff); mIsShowing=true; mIsDropdown=true; WindowManager。LayoutParams p=createPopupLayout (anchor.getWindowToken ()); preparePopup (p); updateAboveAnchor (findDropDownPosition(锚,p发送葡开yoff)); 如果(mHeightMode & lt;0)p。身高=mLastHeight=mHeightMode; 如果(mWidthMode & lt;0)p。宽度=mLastWidth=mWidthMode; p。windowAnimations=computeAnimationResource (); invokePopup (p); }
第11行创建WindowManager.LayoutParams。第12行preparePopup()中:
如果(mBackground !=null) { 最后ViewGroup。LayoutParams LayoutParams=mContentView.getLayoutParams (); int高度=ViewGroup.LayoutParams.MATCH_PARENT; 如果(layoutParams !=零,, layoutParams。身高==ViewGroup.LayoutParams.WRAP_CONTENT) { 身高=ViewGroup.LayoutParams.WRAP_CONTENT; }//当背景是可用的,我们嵌入视图的内容//另一个视图内部拥有可拉的背景 PopupViewContainer PopupViewContainer=new PopupViewContainer (mContext); PopupViewContainer。LayoutParams listParams=new PopupViewContainer.LayoutParams ( ViewGroup.LayoutParams。MATCH_PARENT、身高 ); popupViewContainer.setBackgroundDrawable (mBackground); popupViewContainer。addView (mContentView listParams); mPopupView=popupViewContainer; 其他}{ mPopupView=mContentView; }
如果做了setBackgroundDrawable(新BitmapDrawable());那么mBackground则不为空,则会用PopupViewContainer作为mPopupView(即内容视图)。而PopupViewContainer的dispatchKeyEvent对返回键做了处理,按返回键后其中调用解雇()方法。其onTouchEvent对触摸事件做了处理,其源码:
公共布尔> setBackgroundDrawable (null),然后通过设置视图的关键监听,监听到后做相应的处理。 视图。setOnKeyListener(新View.OnKeyListener () { @Override 公共布尔alt=" android popupwindow用法详解">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
android popupwindow用法详解