http://www.cnblogs.com/mengdd/p/3569127.html
http://topmanopensource.iteye.com/blog/1697101
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0702/1627.html
目录
自适应大小
https://www.iteye.com/blog/handsomeliuyang-1291145
半透明效果
popupWindow.setAnimationStyle(R.style.Animation_ZoomLight);
WindowManager.LayoutParams params=getActivity().getWindow().getAttributes();
params.alpha=0.7f;
getActivity().getWindow().setAttributes(params);
设置宽高wrap_content无效,如何显示正确位置
在显示之前测量宽高
popupWindow.contentView.measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED)
val popViewHeight = popupWindow.contentView.measuredHeight
//我的需求是将popupWindiow 显示在viewItem的右边中间位置
popupWindow!!.showAsDropDown(viewItem, viewItem.width + 10,-viewItem.measuredHeight/2-popViewHeight/2, Gravity.NO_GRAVITY)
showAtLocation理解
https://blog.csdn.net/klx502/article/details/47723499
其中view设置哪个都一样(意思是,不论设置哪个,popwindow的相对参照物都是整个屏幕的根布局)
对于showAtLocation(view,int,x,y)方法显示popupWindow
- 参数二
1.设置Gravity.NO_GRAVITY的话,就相对屏幕左上角作为参照(即原点[0,0]是屏幕左上角)
2.若设置Gravity.LEFT的话,则原点为 [0,1/2屏幕高],即[x=0,y=1/2屏幕高度];
- 参数三、四
popwindow的左上角的x和y,一般是先获取decorView相对于屏幕的坐标,然后结合popwindow的宽高来做一个偏移。
int[] location = new int[2];
decorView.getLocationOnScreen(location);
0 条评论