好的,我正在为 Oreo 使用新的画中画 (PIP) 模式,并使用我计算的自定义纵横比:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x + (size.x / 2);
int height = size.y;
Rational aspectRatio = new Rational(width, height);
PictureInPictureParams.Builder PIPParamsBuilder = new PictureInPictureParams.Builder();
PIPParamsBuilder.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(PIPParamsBuilder.build());
基本上它给了我比默认宽度更大的宽度。我的问题是,当我在横向模式下使用相同的代码时,出现此错误:
java.lang.IllegalArgumentException: enterPictureInPictureMode: Aspect ratio is too extreme (must be between 0,418410 and 2,390000).
at android.os.Parcel.readException(Parcel.java:1946)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.IActivityManager$Stub$Proxy.enterPictureInPictureMode(IActivityManager.java:9750)
at android.app.Activity.enterPictureInPictureMode(Activity.java:2119)
at com.brickx.creartup.Main.startPIP(Main.java:740)
at com.brickx.creartup.Main.onUserLeaveHint(Main.java:751)
at android.app.Activity.performUserLeaving(Activity.java:7151)
at android.app.Instrumentation.callActivityOnUserLeaving(Instrumentation.java:1572)
at android.app.ActivityThread.performUserLeavingActivity(ActivityThread.java:4082)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4058)
at android.app.ActivityThread.-wrap15(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1700)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
日志非常明确:我的纵横比超过了最大值。
但我的问题是:我为什么要处理这个?如果超过它,Android 不能自动将宽度和/或高度设置为各自的最大值吗?
也许我在这里遗漏了一些东西,但我认为我不应该在每次输入 PIP 时检查设备的宽度,以防它超过最大值......