android:configChanges="screenSize" parameter is taking portrait height in landscape mode

1.2k views Asked by At

I'm kind of confused here,I'm creating one application with supporting both portrait and landscape modes.I'm noticing a strange behaviour with "screenSize" parameter as the layout takes full portrait height of the device in landscape mode.Does anybody face the same issue.I'm really stuck here any help would be great.

2

There are 2 answers

9
AudioBubble On

Please try this

android:configChanges="orientation|screenSize"

Inside your activity tag

Happy coding :)

0
DBCrocky On

So, normally, when a configuration value changes that can affect the UI of your current activity happens, Android destroys the activity, then recreates it with the new configuration. This is the preferred method and what happens when you don not have "orientation" or "screenSize" in your android:configChanges attribute. If your app doesn't have any state (other than stuff Android automatically handles, like type in field values), then it should work fine. If you do have some state values, then you should save that state using OnSaveInstanceState, or a ViewModel, and restore that state when the activity is recreated.

When you use the "android:configChanges="orientation|screenSize" attribute it tells Android not to destroy and then recreate the activity when the size/orientation changes. Instead it will call onConfigurationChanged() in your activity, and it is up to you to manually refresh the UI.

All of this is documented here: https://developer.android.com/guide/topics/resources/runtime-changes

I would recommend taking the android:configChanges attribute out of your activity altogether. To prevent the softkeyboard from appearing initially, you can use the attribute:

android:windowSoftInputMode="stateAlwaysHidden"