I have a simple app that works well for phones, with the following structure:
Now, I want to take better advantage of the unused space when the user is
using the app in a tablet or in landscape mode. Pretty much like this:
Is there any way I can make a check (resolution or device type) that I can
switch the xml layout from phone_layout.xml to tablet_layout.xml on onCreate?
OR I should be using fragments for this?
Thanks.
You can make use of the resource buckets.
Basically you will have to create two layout files with the same name in two different resource folders:
res/layout/your_layout.xml
: this will be your default layout for any other devices than the below mentionedres/layout-sw600dp/your_layout.xml
: this layout will be picked by devices with the smallest width of 600 dp (tablets fall into this category)The system is intelligent enough to pick the right layout based on the running device as long as you name your layouts the same.