Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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

For instance look at How to Add/Create Landscape Layout in Android Studio


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...