Android Nougat 7.1.1 showAtLocation(...) 重力不起作用

Kim*_*ano 3 android android-popupwindow android-7.1-nougat

这与这个问题相关: Android Nougat PopupWindow showAsDropDown(...) Gravity notworking

但是,当我应用此修复程序时:

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);
}
Run Code Online (Sandbox Code Playgroud)

它不适用于 Android Nougat 7.1.1。特别是在 Google Pixel 和 Nexus 6p 设备上。

有人解决这个问题了吗?请分享。 https://code.google.com/p/android/issues/detail?id=231487

小智 6

当我将 PopupWindow 的高度从 更改为 时WindowManager.LayoutParams.MATCH_PARENTWindowManager.LayoutParams.WRAP_CONTENT它可以在 Android 7.1 上运行,我不知道原因,但也许你可以尝试一下。

另外,您需要将代码更改为:

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);
}
Run Code Online (Sandbox Code Playgroud)