Universal application (tablet and phone) - what is the best way to structure - multiple xml layouts or show / hide widgets?

I am planning my first real Android app, and I want it to be a universal app (tablet and phone). The layout will consist of three lists that are filled with the previous list (one list always has the same list of items, the second list will be filled based on list one, three lists will be filled based on list 1 and 2), as soon as an item from the list 3 selected, details will be displayed relative to the item. FYI, the data is in the XML file (containment hierarchy), and the details are the nodes of the sheet.

I plan to have two layouts. For a tablet, I will have all three types of list and details on one screen. For the phone, I’m going to make each list take up the whole screen, and when the selected item moves to the next view of the list (with navigation at the top to go to the previous list, as well as information about which choice from previous lists). When an item in the third list is selected, show the details page, which will also have a button for starting (i.e. return to the first list).

I can clearly see the presentation of the tablet, since the simplest (only one screen, without transitions) is all in the /main.xml layout. I also have different layouts for screens of different sizes (layout, layout layout, layout layout, xlarge layout), all of which have the same main.xml at the moment.

So, finally, to my question ... How to use the same code to populate lists with different user capabilities? I see two options (please add additional / better options)

  • For the phone, should I continue to have one layout file (main.xml) and just have all three lists and data on top of each other and through the slide transition, show / hide widgets? (that is, only the first view of the list is visible at first, the second window of the list is hidden, the third view of the list is hidden, details are hidden)

  • Should I have one xml layout for each screen on the phone (main.xml - start list, list2.xml, list3.xml and details.xml)?

To determine if this is a tablet or not, I plan to use the code from a Google I / O application
Development of a universal Android application (phone and tablet)

EDIT (2011/11/29)
Found some good online resources regarding snippets:
http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
http://portabledroid.wordpress.com/2011/06/22/25/
http://portabledroid.wordpress.com/2011/06/23/multi-platform-fragments-part-ii/
and accompanying video:
http://www.youtube.com/watch?v=4BKlST82Dtg

+6
source share
1 answer

You want to read this document on tablet and phone support , but the key to solving your problem is using fragments .

+5
source

Source: https://habr.com/ru/post/902248/


All Articles