0

I have a view on which I would like to place two ListViews that would have position next to each other depending on the screen orientation. It would look like that:

Horizontal screen orientation:

 ___________ ___________
|           |           |
| ListView1 | ListView2 |
|___________|___________|

Vertical screen orientation:

 ___________ 
|           |
| ListView1 |
|___________|
|           |
| ListView2 |
|___________|

From what I have read, I need to use a fragment for each ListView - can it be done in some other way (i.e. just by using two different XML layout files but the same logic)?

syntagma
  • 23,346
  • 16
  • 78
  • 134
  • you can set one xml for portrait orientation and another for landscape. you need two xml files with the same name, the portrait one in the regular layout folder and for the landscape one add a folder - layout-land and place the landscape xml file there. hope this will help ... you can also look at the answers here: http://stackoverflow.com/questions/23712950/android-make-an-element-only-present-in-portrait-view/23713012#23713012 – Guy S Jun 10 '14 at 13:11

3 Answers3

1

You just have to put it under separate folders with different names depending on orientation and resolution, the device will automatically select the right one for its screen settings.

You can do with following approach.

Just create a directory named layout-land and layout-port. Put layout file with same name. Make sure you are using same ids inside layouts.

layout-land
    - myactivity.xml
layout-port
    - myactivity.xml

Android will automatically take layout as per orientation.

Reference : Multiple Screen Support. Read Using configuration qualifiers in it..

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
0

How about having two Layout XMLs placed in layout-land and layout folders. For -land place the list views horizontally and for other vertically.

Easy way out!

Parth Kapoor
  • 1,494
  • 12
  • 23
0

You can check the device orientation in your first activity and then change the orientation of your main linear layout vertical or orientation. Don't forget to change the layout parameters of your listviews parent layout when you change the orientation of the parent layout, because if you are using weights then it might throw error. But if you are not using such attribute it should work fine.