The recommend way to to provide layouts for different screen widths is to include each screen dependent layout in a folder using the layout-swxxdp qualifier:
res/layout-sw600dp/ # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/ # For 10” tablets (720dp wide and bigger)
res/layout-sw600dp-port/ # For 7” tablets in portrait (600dp wide or bigger)
res/layout-sw720dp-port/ # For 10” tablets in portrait (720dp wide or bigger)
Android automatically inflates the right layout according to the screen width.
That's great that Android can figure out which layout to use, but what if I have screen size dependent Java code in my activity class that I need to run? What would the implementation of the following method look like?
// Returns true if the screen width is 600 dp or more
is600dp();
I've seen methods like this
// Returns true if the screen is at least
// approximately 480x640 dp units
private boolean isLarge(){
return (this.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
Now what if my device has a 600dp do screen width, but the above method returns false? Android inflates the right layout, but my device specific code doesn't run.
Am I even making sense?