Android conditional layouts for phones: tablets

I am making an application that is easily accessible and MOSTLY used on phones, but will be CONVENIENT for use on a tablet, if available.

I am familiar with landscape / portrait layouts for individual XML files, but what about different resolutions? This is also a problem for phone-only applications, which is the best way to have scalable layouts.

I use dip values ​​that are density independent but not as efficient as just using percentages that will effectively scale your layout.

I also hard code XML. I IMAGINE that I could programmatically generate a layout by checking the width and height of the screen on EVERY ACTIVITY, but tell me, is there a better way?

+4
source share
1 answer

You can specify additional layouts by specifying the screen size (small, normal, large and xlarge) in the same way as you specify layouts for portrait or landscape orientation.

Here are some examples taken from the Android documentation for this topic.

 res/layout/my_layout.xml // layout for normal screen size ("default") res/layout-small/my_layout.xml // layout for small screen size res/layout-large/my_layout.xml // layout for large screen size res/layout-xlarge/my_layout.xml // layout for extra large screen size res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation 

The book , A Guide for a Busy Coder for Android Development, has a great explanation on this.

+7
source

All Articles