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.

Answers


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


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
    }

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);
}

Need Your Help

FFserver: Securing with HTTP Authentication? (Apache?)

stream ffmpeg webcam security ffserver

Is there some way to secure an ffserver webcam stream using Apache / HTTP Authentication? Some type of Apache proxy perhaps?

Limiting results with a join while not counting joined results?

sql mysql database

Don't know if this is possible, I am looking a writing social network-esque code but need a bit of help.