jdarlan
jdarlan

Reputation: 29

How to create two separate layouts for 10'' and 9.7'' tablets?

I'm developing an application for Android tablets. I've read this Google's guide several times, but something justs doesn't seem right:

I've been testing the app on a Genymotion's Google Nexus 10 (10.1''). Yesterday I bought a 9.7'' tablet to test on a real device, but the interface was as if I set the Android Studio layout preview to Nexus 9 (8.9'').

So I guessed this:

So I moved all my layouts to /layout-xlarge-land/ And began designing a new one to fit my 9.7'' tablet, and put into /layout-large-land/, basing in the 8.9'' Nexus 9 (that looked exactly as in my 9.7'')

But then my surprise was that Android Studio (or actually just Android) treats both 8.9'' (=9.7'') and 10'' as large.

I have tried several answers saying to rename the folder to /layout-sw768dp/, but they don't work.

So I need two folders: one for 10'' tablets and another for 9.7'' (yes, they are not equally treated).

How should I name them?

Upvotes: 0

Views: 1996

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

I need two folders: one for 10'' tablets and another for 9.7''

Those are not meaningful figures, and therefore there is no means of having different resources for them. They are not meaningful, because they do not take aspect ratio into account. Not all Android devices have the same aspect ratio: some are 16:9, some are 16:10, some are 4:3, some are 1:1, some are other things entirely. 10", 9.7", and kin are primarily for marketing purposes.

This is no different than in Web design, where designers don't speak in terms of the diagonal dimension of a browser window all that much.

For technical purposes, while you can use the legacy -large/-xlarge sorts of qualifiers, they were supplanted about four years ago by the -w/-h/-sw qualifiers:

  • -w640dp indicates resources that should only be used on devices whose current width is 640dp (i.e., 4 inches) or larger, where you can supply the number you want where I have 640

  • -h640dp indicates resources that should only be used on devices whose current height is 640dp or larger (again, with customizable values)

  • -sw640dp indicates resources that should only be used on devices whose smallest width, in any orientation, is 640dp or larger (in landscape, the "smallest width" is actually the current height)

This gives you control much like how Web designers use media queries in CSS stylesheets to change CSS rules based on particular heights and widths.

Now, since nobody knows what you think is a 9.7" UI and what you think is a 10" UI, nobody can really help you either consolidate that into one set of layout rules or provide you with qualifier values that will work. You are going to need to determine for yourself where your dividing line is, based on current width, current height, or smallest width. Let's pretend for the moment that you choose 800dp current width as being your dividing line. Your smaller-than-800dp layouts would go in directories like res/layout/ and res/layout-land/. Your 800dp-or-larger layouts would go in res/layout-w800dp/.

I have tried several answers saying to rename the folder to /layout-sw768dp/, but they don't work.

You may wish to consider editing your question and explaining what "they don't work" means.

Upvotes: 1

Related Questions