如何在 android 中调整画中画模式

How to resize PIP mode in android

我正在尝试在我的应用程序中实现画中画模式。我正在 PIP 模式下实现 google 地图,但我无法调整全屏地图的大小。它总是放大地图中心点。我已经完成了与此问题相关的研发,但没有找到任何合适的答案。基本上,我需要像 Whatsapp app pip Screen 这样的布局在我的应用程序上如何实现?我的代码在这里:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

        Display display=getWindowManager().getDefaultDisplay();
        Point size=new Point();
        display.getSize(size);
        int width=size.x;
        int height=size.y;
        Rational aspectRatio=new Rational(width,height);
        PictureInPictureParams params = new PictureInPictureParams.Builder()
                .setAspectRatio(aspectRatio).build();
        enterPictureInPictureMode(params);
    }

这是清单代码:

<activity android:name=".activities.MainActivity"
        android:supportsPictureInPicture="true"
        android:resizeableActivity="true"
        android:launchMode="singleTask"
        android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"/>

在这段代码中,我有这样的屏幕

我想要

我该如何解决这个问题?

提前致谢!!

只需更改您的此代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

    Display display=getWindowManager().getDefaultDisplay();
    Point size=new Point();
    display.getSize(size);
    int width=size.x;
    int height=size.y;
    Rational aspectRatio=new Rational(width,height);
    PictureInPictureParams params = new PictureInPictureParams.Builder()
            .setAspectRatio(aspectRatio).build();
    enterPictureInPictureMode(params);
}

Rational aspectRatio = new Rational(3, 4);

        PictureInPictureParams params = new PictureInPictureParams.Builder()
                .setAspectRatio(aspectRatio).build();
        enterPictureInPictureMode(params);