简体   繁体   English

android:configChanges =“screenSize”参数在横向模式下采用纵向高度

[英]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. 因此,通常情况下,当配置值发生变化会影响当前活动的UI时,Android会销毁该活动,然后使用新配置重新创建活动。 This is the preferred method and what happens when you don not have "orientation" or "screenSize" in your android:configChanges attribute. 这是首选的方法,当你在android:configChanges属性中没有“orientation”或“screenSize”时会发生什么。 If your app doesn't have any state (other than stuff Android automatically handles, like type in field values), then it should work fine. 如果你的应用程序没有任何状态(除了Android自动处理的东西,比如键入字段值),那么它应该可以正常工作。 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. 如果确实有某些状态值,则应使用OnSaveInstanceState或ViewModel保存该状态,并在重新创建活动时恢复该状态。

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. 当你使用“android:configChanges =”orientation | screenSize“属性时,它告诉Android不要销毁,然后在大小/方向改变时重新创建活动。相反,它将在你的活动中调用onConfigurationChanged(),这取决于你手动刷新UI。

All of this is documented here: https://developer.android.com/guide/topics/resources/runtime-changes 所有这些都记录在这里: https//developer.android.com/guide/topics/resources/runtime-changes

I would recommend taking the android:configChanges attribute out of your activity altogether. 我建议完全从你的活动中取出android:configChanges属性。 To prevent the softkeyboard from appearing initially, you can use the attribute: 要防止软键盘最初出现,您可以使用以下属性:

android:windowSoftInputMode="stateAlwaysHidden" 机器人:windowSoftInputMode = “stateAlwaysHidden”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将人像旋转到风景时,我要关闭力量,我尝试了android:configChanges =“ keyboard | keyboardHidden”并以人像模式工作吗? - Getting Force Close when rotating portrait to landscape and I tried android:configChanges=“keyboard|keyboardHidden” and working in portrait mode? Android:拍摄和保存照片,人像模式/风景模式 - Android: Taking and saving picture, portrait mode/landscape mode Android Manifest:configChanges:screenSize不可用 - Android Manifest: configChanges:screenSize is not available 纵向和横向方向,并在片段中设置android:configChanges =“ orientation” - portrait and landscape orientations and set android:configChanges=“orientation” in fragment 使用android:configChanges =” orientation | screenSize” />并在方向变化时弄乱了我的景观布局 - Using android:configChanges=“orientation|screenSize”/> And It is Messing Up My Landscape Layout on Orientation change 在 AndroidManifest.xml 中添加 android:configChanges=“orientation|screenSize”后,横向布局没有改变 - Orientation Layout not changing for landscape after adding android:configChanges=“orientation|screenSize” in AndroidManifest.xml 纵向模式下的Android Landscape VideoView - Android Landscape VideoView in portrait mode 适用于Android应用程序的横向和纵向模式 - Landscape and portrait mode for android application 平板电脑Android中的横向和纵向模式 - Landscape and portrait mode in tablet Android Android 中的横向模式更改为纵向 - Landscape Mode change to portrait in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM