Ansh Sharma
Ansh Sharma

Reputation: 39

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 ?

Upvotes: 0

Views: 151

Answers (4)

Pankaj Arora
Pankaj Arora

Reputation: 10274

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!!

Upvotes: 0

princepiero
princepiero

Reputation: 1323

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.

Upvotes: 0

Shruti
Shruti

Reputation: 5591

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.

Upvotes: 1

Beginner
Beginner

Reputation: 1424

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.

Upvotes: 3

Related Questions