When making apps for Android 3.x, you could basically just check if the device was in landscape to see if it could fit multiple fragments side by side. But this is only because you were basically guaranteed that the device is a tablet.
With the introduction of the compatibility library and android 4.0, I can't think of what I would consider as a 'good' way to determine if I can get away with side by side fragments or should revert to standard one fragment per 'screen.'
In the NewsReader example app, Google has a special values file for every common resolution, each with a Boolean value for whether the resolution should support the 2 fragment layout, but I think this way is poorly conceived. The only way I can think of is to check the size of the screen (to guess if it is a tablet or at least big enough to not ruin the layout), and then check the orientation.
So if anyone out there has an idea how to easily and efficiently check this, please let me know!
You can actually see the screen size type (small, normal, large, etc) by using the following:
getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK
That'll return an int that you can check against any of the following:
Configuration.SCREENLAYOUT_SIZE_SMALL
Configuration.SCREENLAYOUT_SIZE_NORMAL
Configuration.SCREENLAYOUT_SIZE_LARGE
Configuration.SCREENLAYOUT_SIZE_UNDEFINED
Then you can check for orientation, using
getResources().getConfiguration().orientation
Which will match any of the following possibilities
Configuration.ORIENTATION_PORTRAIT
Configuration.ORIENTATION_LANDSCAPE
Configuration.ORIENTATION_SQUARE
Configuration.ORIENTATION_UNDEFINED
With this you can essentially simulate the multiple views by adding your fragments as space allows based on screen size and orientation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With