第一种:使用showAtLocation方法
if (Build.VERSION.SDK_INT != 24) {
brandPopup.showAsDropDown(parent);
} else { // 获取控件的位置,安卓系统>7.0
int[] location = new int[2];
parent.getLocationOnScreen(location);
brandPopup.showAtLocation(parent, Gravity.NO_GRAVITY, location[0], location[1] + parent.getHeight());
}
第二种:
popwindow重写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);
}
网友评论