简体   繁体   中英

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

我在这里很困惑,我正在创建一个支持纵向和横向模式的应用程序。我注意到“screenSize”参数的奇怪行为,因为布局在横向模式下占据设备的完整纵向高度。是否有人面对同样的问题。我真的被困在这里任何帮助都会很棒。

Please try this

android:configChanges="orientation|screenSize"

Inside your activity tag

Happy coding :)

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM