我想在不调用onCreate方法的情况下更改布局。我还在我的活动中定义了android:configChanges="orientation|keyboardHidden",但它没有调用onCreate方法,但是在横向模式下布局没有适当地调整。
我的当前布局如下所示。
在横向模式下更改方向后,它看起来像这样:
但是在横向模式下,我希望得到以下结果。
是否有任何自动相邻属性?
我该怎么做?
我的当前布局如下所示。
![alt text](https://istack.dev59.com/2QHYX.webp)
![alt text](https://istack.dev59.com/8utAA.webp)
![alt text](https://istack.dev59.com/WaUqm.webp)
我该怎么做?
当视图从纵向模式转换为横向模式时,没有自动调整属性。
对于要在横向模式下显示��图像
创建一个filename.xml文件并为横向模式设计您的布局。 将文件名设置为您在活动中使用的布局文件夹中以前的xml文件的名称。
在res/中创建名为layout-land的文件夹,然后将该filename.xml文件保存在res/layout-land文件夹中。
当方向从纵向模式更改为横向模式时,它将自动调用res/layout-land/filename.xml。
或者您也可以使用
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
//your code
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//your code
}
}
把这个放在你的清单里,兄弟。。
android:configChanges="orientation|keyboardHidden|screenSize|uiMode"
它解决了你和我的问题:D
你只需要在 AndroidManifest.xml 文件中的 activity 标签中添加 android:configChanges="orientation|keyboardHidden",就可以解决问题了。