Android gadgets are found in various screen sizes and densities. It is here where fragments make planning the layouts for phones and tablets simple. We can progressively include and expel sections from an activity which makes it conceivable to plan adaptable UIs.
Generally a single pane design is favored for telephones and multi-pane formats are utilized for tablets with a specific end goal to use the additional space which is found in tablets. The Open Event Android App on tablet view appeared to be identical for a versatile client and accordingly it had a considerable measure of free space which could be used for effective UI for tablet clients. A two-pane design is utilized for the application where the navigation view is on the left side while the item clicked on the navigation view is on the right side.
Steps involved for incorporating a two-pane layout
The steps that need to be followed for the app to support a two-pane layout are as follows:
- Create a layout-sw600dp (for small tablet users) or layout-sw720dp (for large tablet users) in the res directory.
- The name of files should be same for those within layout/ and layout-sw600dp/ to provide a support for a two-pane layout.
The layout/activity_main.xml structure of the app looks like this:
The layout-sw600dp/activity_main.xml structure of the app looks like this:
- Now in the MainActivity.java file of the app we took a boolean variable mTwoPane which was true if during runtime findViewById(R.id.drawer) didn’t exist as a drawerlayout is used as a root view for the activity_main.xml in layout/ folder but not in layout-sw600dp folder.
- All the parts of the MainActivity.java which had a drawerlayout variable were now put in an “if” condition checking if the mTwoPane boolean value is false then execute the statement otherwise set the drawerlayout to lock mode.
This helped us accomplishing a two-pane layout in the tablet layout of the app thus helping in using the extra space in a more efficient manner.
- This link highlights the best practices to be followed for designing an Android App on tablets and handsets. (https://developer.android.com/guide/practices/tablets-and-handsets.html)
- This link is about how we can support different screen sizes in Android. (https://developer.android.com/training/multiscreen/screensizes.html)