We have already seen configuration qualifiers such as layout-large
or layout-xhdpi
in The Android Studio guided tour section from Chapter 3, Exploring Android Studio. Here, we will refresh and expand our understanding of them.
We can begin to remove the reliance on the controller layer to influence the app layout by using configuration qualifiers. There are configuration qualifiers for size, orientation, and pixel density. To take advantage of a configuration qualifier, we simply design a layout in the usual way that is optimized for our preferred configuration and then place that layout in a folder with a name that Android recognizes as being of that particular configuration.
So, if we want to have a different layout for landscape and portrait, we would create a folder called layout-land
in the res
folder and place our specially designed layout within it. When the device is in the portrait position, the regular layout from the layout
folder would be used, and when it is in landscape, the layout from the layout-land
folder would be used.
If we are designing for different sizes of screen, we place layouts into folders with the following names:
layout-small
layout-normal
layout-large
layout-xlarge
If we are designing for screens with different pixel densities, we can place XML layouts into folders with names like these:
layout-ldpi
layout for low DPI deviceslayout-mdpi
layout for medium DPI deviceslayout-hdpi
layout for high DPI deviceslayout-xhdpi
layout for extra high DPI deviceslayout-xxhdpi
layout for extra, extra high DPI deviceslayout-xxxhdpi
layout for extra, extra, extra high DPI deviceslayout-nodpi
layout for devices with a DPI that you have not otherwise catered forlayout-tvdpi
layout for TVsWhat exactly qualifies as a low, high, or extra high DPI can be researched at the link in the next information box. The point here is the principle, and we will do something practical with this knowledge in the next mini app.
You might also remember that we added icons of different sizes into folders with names such as drawable-mdpi
and drawable-hdpi
when we started the Note To Self app in Chapter 12, Having a Dialogue with the User. This was because Android would use different graphics based upon the screen density of the device our app is being run on.
It is worth pointing out that what we have just discussed is a long way from the whole story regarding the configuration qualifiers, and as with design, it is worth putting this on your list of things to study further.
As so often, the Android developer site has lots of detailed information on handling layouts for different devices. Try out http://developer.android.com/guide/practices/screens_support.html for more information.
Let's try out some device qualifiers now.
3.142.173.227