Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

android - How to Dynamically Change LinearLayout Orientation Depending on Device Orientation

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...