2

After reading though the document here, I'm still a little confused by how I should be using the naming scheme to correctly set layouts for different devices.

I specifically need layouts for the Galaxy S3, Nexus 7 and Asus Transformer.

I am current using:

S3:
    layout-normal
    layout-normal-land

Nexus 7:
    layout-large
    layout-large-land

Transformer:
    layout-xlarge
    layout-xlarge-land

Is this correct, or is there a way to more specifically target devices?

Chuck Finley
  • 295
  • 1
  • 4
  • 12
  • 1
    Don't forget `dimens.xml` -- I found that it reduces the number of layout files significantly, especially between normal and large. Also, there's no `-normal` but rather `layout` and `layout-land`. – 323go Mar 11 '13 at 22:06

1 Answers1

3

Your example uses the old way of small/medium/large/xlarge) buckets. This is problematic, because for instance both the Galaxy Tab 7.0 (1024x600) and the Nexus 7 (1280x800) qualify as large. The Nexus 7 can handle tablet layouts, but the old Tab 7.0 is generally better off with a phone layout. The old system doesn't support this distinction, so, starting with Honeycomb, you can use the new way, which doesn't rely on buckets but uses the actual screen size in dp to decide which layout to use. This gives you much more control over which layout is selected when.

Check out the section Declaring Tablet Layouts within that document you linked. It introduces the dp-based selectors. The three devices you mention all use newer Android versions that can benefit form the "sw720dp" approach.

There's a bit more to it, because if your minimum target version is Gingerbread or earlier, you basically have to support both the s/m/l/xl buckets and the newer dp-based selectors. At first glance, this means you'd have to copy all your tablet layouts into multiple directories and manually keep them in sync. Fortunately, there's a trick to make this work without copy/pasting your layout definitions. It involves using layout aliases in the values/ section. How to do that is documented in the multiscreen section of the Android tutorial.

Barend
  • 17,296
  • 2
  • 61
  • 80