Forums Register Login

Advice on the use of compound resource qualifiers

+Pie Number of slices to send: Send
Hi Satya / Dave,

When designing user interfaces one can take into account e.g. designing for medium-density screens (mdpi), or high-density screens (hdpi) and e.g. tablets (xlarge screen size). But you can also design layouts for specific versions e.g. v11. To complicate things further you can combine a lot of these qualifiers into one compound qualifier, for example into something like this ./res/layout-land-large-v11.

The question: What is your experience and advice on designing layouts for various devices and versions. Do you pick a couple of these qualifiers? Which ones and why? Have you ever used a version qualfier and for what other reason than making use of the latest UI widgets?

Thanks again!

Cheers,

Johan
+Pie Number of slices to send: Send
You are right on. We covered this topic in the book in a couple of places actually. And you're right, things can start to get rather hairy if you start adding a bunch of qualifiers to the resource directory names. In general I only worry about the -land/-port, and -small/-normal/-large for layouts, and -hdpi and -ldpi for drawables. I haven't done other languages but of course if you did, you'd use the language qualifiers on /res/values directories where all the strings are. The directories without qualifiers are really your defaults, since Android will look in these last if it can't find a match in a more specific directory. So sometimes I'll use layout/ and layout-land/ where the former holds my layouts for portrait mode. You can really make things tough on yourself if you make too many resource versions. One more quick note on this: if you make versions of your app for other languages, you may need to tweak the layouts to accommodate words that are shorter or longer in the other languages.

Something else that can make your life easier (or more complicated depending on your personality) is the ability to do includes within XML files. For layouts, this means you could construct a common chunk of layout in layout/common1.xml. Then you could define the layouts you're going to use in layout-port/main.xml and layout-land/main.xml and within each of those, you could use <include layout="@layout/common1" /> . From your code, you refer to R.layout.main which will pick up the appropriate one, and at the same time you only need to define the common layout in one place.

- dave
+Pie Number of slices to send: Send
Hi Dave,

Thanks for the answer. In my experience I am spending a lot of time on getting the layouts right, so I want to minimize the number of layout resources. Your answer helps me not to go overboard with trying to implement for every possible screen size or version. I will start using the qualifiers you suggested. The Graphical Layout editor in the ADT plugin keeps getting better and better thought, so I will definitely use that more often!

Cheers,

Johan
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1311 times.
Similar Threads
help with search() method
Trying to create a liquid class
Android question
How to force landscape under all circumstances?
Regex: several of one type of char or one of another
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:32:30.