如何根据设备方向动态更改LinearLayout方向 [英] How to Dynamically Change LinearLayout Orientation Depending on Device Orientation

查看:230
本文介绍了如何根据设备方向动态更改LinearLayout方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当设备更改方向时,如何更改LinearLayout的方向? * .xml的关联* .kt文件需要进行哪些更改?

How do I change the orientation of a LinearLayout when a device changes orientation? What changes would be needed in the *.xml's associated *.kt file?

例如,设备处于纵向模式,并显示垂直方向的LinearLayout.当设备旋转并变为横向时,LinearLayout应该具有水平方向.

For example, the device is in Portrait and displays a LinearLayout with a vertical orientation. When the device turns and becomes Landscape, the LinearLayout should have a horizontal orientation.

我想根据配置更改会调用两种不同的布局,但是我不确定.

I imagine that two different layouts would be called depending on the configuration change but I'm not sure.

推荐答案

您需要为布局使用单独的文件夹:layout用于纵向模式,layout-land用于横向模式,并放置两个单独的xml文件with the same name在每个人中.

You need to use separate folders for your layouts : layout for portrait mode and layout-land for landscape mode, and put two separate xml files with the same name in each one.

其中一个具有LinearLayout垂直方向的xml文件和另一个带有LinearLayout水平方向的xml文件.

One of xml files with LinearLayout with a vertical orientation and another xml file with LinearLayout with horizontal orientation.

例如查看如何添加/创建景观布局在Android Studio中

这篇关于如何根据设备方向动态更改LinearLayout方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆