如图所示
Rect visibleFrame = new Rect();
anchor.getGlobalVisibleRect(visibleFrame);
int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
setHeight(height);
和
int[] location = new int[2];
anchorView.getLocationOnScreen(location);
int tempHeight = getHeight();
if (tempHeight == WindowManager.LayoutParams.MATCH_PARENT || getScreenHeight(anchorView.getContext()) <=
tempHeight) {
setHeight(getScreenHeight(anchorView.getContext()) - location[1] - getHeight());
}
super.showAsDropDown(anchorView, Gravity.NO_GRAVITY, xoff, yoff);
super.update();
都几把不管用,
这是什么原因造成的:主要是popupwind的页面测量不准造成的
解决方案1:
(老子就要自己写,不想用第三方)
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
if (Build.VERSION.SDK_INT >= 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
Activity activity = (Activity) anchor.getContext();
Rect outRect1 = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect1);
int h = outRect1.height() - rect.bottom+ ScreenUtils.getStatusBarHeight();
// int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor, xoff, yoff);
}
其中ScreenUtils是第三方的,沉侵式状态栏
implementation 'com.jaeger.statusbarutil:library:1.5.1'
第二种就是采用第三方
这三个都能用,很完美,能上能下,能前能后,动作多花样多,包顾客满意