Maddie_J
Maddie_J

Reputation: 171

Landscape Mode not working in Android Studio

I have created Android layout resource files for landcape mode for all different screen sizes such as, small, large, medium and extra large , however, when I run the app it does not work in landscape mode as half of the buttons, images are missing from the screen.

I have also included the below line in the android Manifest file.

android:configChanges="keyboardHidden|orientation|screenSize"

Please advice how I can make andriod aware of when to use the landscape and portrait mode.

Upvotes: 1

Views: 3229

Answers (3)

Aniruddha K.M
Aniruddha K.M

Reputation: 7521

This is happening because you have added android:configChanges="keyboardHidden|orientation|screenSize" in your manifest which means the orientation changes will not occur hence your landscape layout never gets initialised. By default the android behaviour is that when the mobile is rotated the current activity is destroyed and new one is created. Remove that line and try

Upvotes: 2

Nazmus Sakib
Nazmus Sakib

Reputation: 21

okay I am giving an example.....i had a imageview in my layout. when I go to portrait mode it is set one image. and when I go to landscape mode it changes to another image.

ImageView headerimage= (ImageView) findViewById( R.id.headerimage);
int orientation = getResources().getConfiguration().orientation;

if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
    headerimage.setBackgroundResource(R.drawable.splash_icon_landscape);
} else {
    headerimage.setBackgroundResource (R.drawable.splash_icon_portrait);
}

Upvotes: 0

Nazmus Sakib
Nazmus Sakib

Reputation: 21

In the java file of an activity this is how you can recognize if you are in a Landscape mode or portrait mode.

    int orientation = getResources().getConfiguration().orientation;

    if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
        //do something
    } else {
        //do something
    }

Upvotes: 0

Related Questions