1. 定位的问题
ppw提供了两种show的方式
showAsDropDown
showAtLocation
调用这两个方法都需要传入一个用于定位的view,showAsDropDown叫anchor,showAtLocation叫parent
showAsDropDown是在anchor的下方将ppw显示出来,没怎么用这个,暂且空下.
showAtLocation是在所在的window里面定位,parent只是为了提供window的一些数据
parent: a parent view to get the android.view.View.getWindowToken()
token from
所以不管parent在什么位置,有多大,在Gravity设定好之后,ppw出现的位置都是给予window的四个角,然后再根据偏移的参数具体定位。
再说偏移参数x,y,并不是正的就向右下,负的就向左向上,而是基于四个角的位置向内
比如y>0, 如果设置Gravity.TOP,就是向下偏移,Gravity.BOTTOM就是向上偏移
2. ppw宽度的问题
我的ppw中包含一个listview,不管怎么设置宽度为自适应,show出来的时候宽度都是matchparent的。
有人说listview在getview之前,不知道宽度是多少,所以就设为最大宽度了,我也没有去细究原因。
参考了两个地方:
http://blog.csdn.net/zgyulongfei/article/details/7973063
http://stackoverflow.com/questions/4085093/how-to-set-the-width-of-the-listview-in-a-popupwindow-on-android/12384748#12384748
都没解决问题,无奈只能使用最后的杀手锏:设置一个固定的宽度
int width = mContext.getResources().getDimensionPixelSize(
R.dimen.spinner_item_width);
this.setWidth(width);
在构造函数里面设定一个固定的宽度,奏效,好无奈的感觉,不过listview里面的item的宽度也是这个,所以还好
3. 当快速点击ppw中listview的item时,item会连同背景一同消失,变透明
stackoverflow上面也有这个问题:
http://stackoverflow.com/questions/8977197/a-button-in-a-popupwindow-goes-transparent-when-clicked-quickly
就是快速的点击会出现,慢慢的点击正常。
仍未解决。