简体   繁体   中英

Change in layout with change in orientation

Hi is it possible that in my android application buttons which are there in vertical orienatation change to tabs in horizontal orientation . So they can fit better for tablets ?

one way is to create 2 folders called layout-land and layout-port, write 2 different xml's with same name and put them in layout-land and layout-port

for example if you have a home.xml

If you put home.xml in layout-port folder, when your device is in portrait orientation it will use the file: layout-port/home.xml.

If you put home.xml in layout-land folder, when your device in landscape orientation it will use the file: layout-land/home.xml.

You have to create separate XML files for portrait and landscape modes and place it in different directories. The device will automatically select the right one. You can use the following directory structure

res/layout/my_layout.xml   
res/layout-land/my_layout.xml

For more details read this doc .

Yes, it's definitely possible.

Have you check this one ? Basically it's using the Resources in your Android project. You can create the following folders:

res/layout/           //portrait
res/layout-land/      //landscape

Have a layout with the same name but different content depending on what you want.

for 7 inch tablet:-make a new folder in res/layout-sw600dp-port for portrait mode and res/layout-sw600dp-land for landscape mode

for 10 inch tablet:-make a new folder in res/layout-sw720dp-port for portrait mode and res/layout-sw720dp-land for landscape mode

for phone layout upto 5 inch screen,just design your screen in layout folder

hope this will help you !!Happy Coding!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM