This week's book giveaway is in the Functional programming forum.
We're giving away four copies of Functional Design and Architecture and have Alexander Granin on-line!
See this thread for details.
Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Advice on the use of compound resource qualifiers

 
Ranch Hand
Posts: 105
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 51
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic