Home > OS >  Android app left spacing when landscape mode
Android app left spacing when landscape mode

Time:12-25

Hi I currently am creating an app where I am forcing one activity to be in landscape mode.

It works but I keep getting left spacing as if there is an action bar / status bar still to the left of the screen.

enter image description here

Here is my theme:

<style name="Theme.MyApp" parent="Theme.AppCompat.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <!--<item name="android:windowFullscreen">true</item>-->
    <item name="android:windowTranslucentStatus">true</item>
</style>

Which works fine in all the activities other the the one with this code in the manifest file:

    <activity
        android:name=".MyActivity"
        android:exported="false"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="sensorLandscape"
        android:theme="@style/Theme.MyApp"/>

Any help would be great.

Thanks!

CodePudding user response:

After searching the web for a while I found this page:

https://developer.android.com/guide/topics/display-cutout

It turns out that in Android 9 (API level 28) and higher there is display cutouts. Which by default content gets rendered into the cutout area when displayed in portrait mode only other wise when in landscape mode it content is letterboxed (doesn't render content into the cutout area).

LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT - With this default setting, content renders into the cutout area when displayed in portrait mode, but content is letterboxed when displayed in landscape mode.

So all I need to do in order to fix my problem is to set the cutout mode to shortEdges.

LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES - Content renders into the cutout area in both portrait and landscape modes.

By adding the following line to my theme style.

<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
  • Related