Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Advice on the use of compound resource qualifiers

 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave MacLean
author
Ranch Hand
Posts: 49
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic