Android Nougat 7.1.1 showAtLocation(...)重力不起作用 [英] Android Nougat 7.1.1 showAtLocation(...) Gravity not working
问题描述
这与此问题有关:
Android牛轧糖PopupWindow showAsDropDown (...)重力不起作用
但是,当我应用此修复程序时:
However, when I applied this fix:
if (android.os.Build.VERSION.SDK_INT >=24) {
int[] a = new int[2];
anchorView.getLocationInWindow(a);
popUp.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0 , a[1]+anchorView.getHeight());
} else{
popUp.showAsDropDown(anchorView);
}
在Android Nougat 7.1.1上无法使用。特别是在Google Pixel和Nexus 6p设备上。
It doesn't work on Android Nougat 7.1.1. Particularly on Google Pixel and Nexus 6p devices.
有人能解决此问题吗?请分享。
https://code.google.com/p/ android / issues / detail?id = 231487
Has anybody got a fix for this? Please share. https://code.google.com/p/android/issues/detail?id=231487
推荐答案
当我从更改PopupWindow的高度时WindowManager.LayoutParams.MATCH_PARENT
到 WindowManager.LayoutParams.WRAP_CONTENT
,它可以在Android 7.1上运行,我不知道原因,但是也许可以
When I change PopupWindow's height from WindowManager.LayoutParams.MATCH_PARENT
to WindowManager.LayoutParams.WRAP_CONTENT
, it works on Android 7.1, I don't know the reason, but maybe you can try it.
另外,您需要将代码更改为:
Also, you need to change your code to:
if (android.os.Build.VERSION.SDK_INT == 24) {
int[] a = new int[2];
anchorView.getLocationInWindow(a);
popUp.showAtLocation(((Activity)mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0 , a[1]+anchorView.getHeight());
} else{
popUp.showAsDropDown(anchorView);
}
这篇关于Android Nougat 7.1.1 showAtLocation(...)重力不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!