1

Today I started trying to optimize my application for landscape mode. But I just cannot get my application to run in landscape mode, there are no settings that I have enabled to force portrait.

I am showing my placeholder screen as an example.

I also double checked that auto rotate in my AVD is enabled. I have this problem on every AVD.

Declared like this in my manifest.

<activity
        android:name=".PlaceholderActivity"
        android:theme="@style/AppTheme.NoActionBar" />

My layout looks like this.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_material_light"
android:orientation="vertical"
android:animateLayoutChanges="true" >

<View
    android:id="@+id/icon"
    android:layout_width="350dp"
    android:layout_height="350dp"
    android:layout_centerInParent="true"
    android:background="@drawable/feedyr_full" />

<ProgressBar
    android:id="@+id/progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/icon"
    android:layout_centerHorizontal="true"
    android:visibility="visible" />

<include
    layout="@layout/helper_error"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/icon"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

And my Theme looks like this.

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:colorButtonNormal">@color/colorAccent</item>

    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

There is also nothing is my class that's forcing portrait

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_placeholder);

    config = FirebaseRemoteConfig.getInstance();
    model = Model.getInstance();
....

My placeholder screen on Nexus 9 running 7.1

What am I missing?

Ruben Aalders
  • 624
  • 6
  • 20

4 Answers4

1

Try setting the activity orientation to sensor :

<activity
    android:name=".PlaceholderActivity"
    android:theme="@style/AppTheme.NoActionBar" 
    android:orientation="sensor"/>
Nika Kurdadze
  • 2,502
  • 4
  • 18
  • 28
1

in your AndroidManifest

<activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" />

and in MainActivity.java

public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation== Configuration.ORIENTATION_PORTRAIT)
        {

        }
        else  if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {

        }
    }

hope it`s help

Elsunhoty
  • 1,609
  • 14
  • 27
-1

Don't ask me why, but suddenly the landscape mode works. I pressed the screen rotation buttons on the right menu. When it went back in landscape it suddenly worked. Did this before so don't know why it suddenly started to work.

I did not change anything in my code, theme, manifest or layout...

AVD in landscape mode

Ruben Aalders
  • 624
  • 6
  • 20
-1

Try to enable the emulator screen rotation mode to work.

OdisBy
  • 15
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 14 '22 at 17:45