最近用7.0的android手机测试项目,发现popwindow的showAsDropDown失效了,
不过最终找到了两种解决方案:
1、重写showAsDropDown方法:
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT == 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
2、使用showAtLocation方法:
if (Build.VERSION.SDK_INT >= 24) {
int[] point = new int[2];
v.getLocationInWindow(point);
mPopWindow.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, point[1] + v.getHeight());
} else {
mPopWindow.showAsDropDown(v);
}
网友评论