为什么我的应用程序无法在某些虚拟设备中以横向模式启动

问题描述

我在AndroidManifest.xml中将screenorientation设置为横向。这对于Android Studio中大多数模拟的设备都可以正常工作。

   <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true">
        <activity
            android:name=".FullscreenActivity"
            android:screenorientation="landscape"
            android:configChanges="orientation|keyboardHidden|screenSize"

            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

和在OnCreate

requestwindowFeature(Window.FEATURE_NO_TITLE);
getwindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_fullscreen);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
FullscreenActivity.context = getApplicationContext();
getSupportActionBar().hide(); 

但是对于Nexus 9而言,该功能无法正常工作,我的应用仍处于纵向模式,这会使我的图像失真。

enter image description here

我希望会是这样:

enter image description here

两者的启动方向均为纵向。我想拥有一个仅适用于景观的应用程序

解决方法

我发现的解决方案是将最小长宽比强制为1.3

android:minAspectRatio="1.3"

并设置

android:resizeableActivity="false"

使用这些选项,如果活动处于纵向模式,则活动会在屏幕的一部分内开始,因此图像不会失真

enter image description here