For reference: http://developer.android.com/guide/practices/screens_support.html
The old style size quantifiers are "deprecated":
A set of four generalized sizes: small, normal, large, and xlarge
Note: Beginning with Android 3.2 (API level 13), these size groups are
deprecated in favor of a new technique for managing screen sizes based
on the available screen width. If you're developing for Android 3.2
and greater, see Declaring Tablet Layouts for Android 3.2 for more
information.
I was hoping that devices with 3.2+ would still use resources declared in drawable-large-mdpi, or layout-xlarge, but this doesn't seem to be the case.
I have a test project that contains a layout file for each of these sizes:
layout-sw600dp
layout-720dp
layout-xlarge
layout
On a 10" Motorola XOOM running Android 4.0.x, the device picks the layout in the layout-720dp folder. If that folder doesn't exist, it picks the layout in the layout-sw600dp folder! Why doesn't it pick the layout in layout-xlarge?
Even more strange, is I have drawables in these folders:
drawable-sw600dp-mdpi
drawable-xlarge-mdpi
The 10" Motorola XOOM from above, picks the image from drawable-sw600dp-mdpi. Why doesn't it pick the drawable in drawable-xlarge-mdpi?
Should we not expect the xlarge quantifier to work at all above Android 3.2?
Does this mean I have to duplicate all assets in the drawable-xlarge-mdpi folder, into the drawable-sw720dp-mdpi folder? (To support Android 3.0, 3.1 AND 3.2+?)
Hopefully I am just missing something simple here. Please advise.
From my understanding, for Android 3.2+, if you have at least one folder that uses the new size quantifiers then it assumes that you are using these new size quantifiers everywhere. So this is the reason why it ignores layout-xlarge or any other folder that uses the old quantifiers.
With regard to backward compatibility, you'll have to use in your project both types of quantifiers. The old ones will be used for API < 3.2 and the new ones for API >= 3.2. To avoid duplication, for the layouts you can use aliases. However, for drawables, I don't know of any solution to avoid duplication.
Related
I'm having both layout folders "layout-v10" and "layout-hdpi" in my application. However, as some gingerbread(which is API Level 10) devices also are hdpi screen size, the layouts under the "layout-hdpi" folder is getting inflated. I want to force the layout from "layout-v10" folder to be inflated for all gingerbread devices even if it is a hdpi. Is there any way to do so?
I read this link http://developer.android.com/guide/practices/screens_support.html couldn't figure out what can be done to solve my problem.
to keep layouts looking good in all devices we don't provide folders like "layout-hdpi", etc.
U need to keep your resources in drawable-hdpi, drawable-xhdpi, etc. as mentioned in the android developers guide. The android system chooses the correct folder based on the screen density. This works independent of the api version you are using, the layout will look good in all api levels if you are defining your resources correctly acc. to different screen densities.
I have the following folders for layouts :
layout,
layout-large,
layout-xlarge,
layout-sw720dp
As far as I know, For Android 3.2+, if you have at least one folder that uses the new size quantifiers then it assumes that you are using these new size quantifiers everywhere and ignores any other folder that uses the old quantifiers.
Since I have one folder (i.e. layout-sw720dp) with the new quantifier, I would expect Nexus 7 to pick layouts from the default layout folder. But it is picking the layout from layout-large folder. Can someone please help me understand why?
Just add the same files you have in layout-large to layout-sw480dp or reference the layout from within there.
Anyway: As most devices below 3.0 are phones which are most likely not large nor xlarge and there are nearly no devices out there running android 3.0 or 3.1, I strongly recommend to drop layout-large and layout-xlarge completely and just stick to the new folders.
Here I found the solution to my question:
For Android 3.2+, if you have at least one folder that uses the new size quantifiers then it assumes that you are using these new size quantifiers everywhere and ignores any other folder that uses the old quantifiers.
But the way Android finds out whether you have a folder with new size quantifier is slightly different.
It checks for new size quantifier folders only equal to and below the sw of the device that it's running on.
For example, for Nexus 7 Android would look for folders in the order sw600dp, sw480dp, sw360dp, sw320dp and finally if none of those are present it picks from layout folder. sw720dp though present is not taken into consideration since it is out of range for a nexus 7 device.
The requirement for the app is that it should work on all devices. To support this I have
following layout defs-
layout/
layout-land/
layout-sw400dp-port/
layout-sw400dp-land/
layout-sw600dp-port/
layout-sw600dp-land/
layout-sw7200dp-port/
layout-sw7200dp-land/
its working fine for 7" and 10" tablets.
for the sw400dp devices ie 5" devices like Samsung Note etc, they are using layout/ and
layout-land/. How can I force these devices to use
layout-sw400dp-port/ and layout-sw400dp-land/
You can't
The original Note runs GingerBread (2.3) and the sw- identifiers only work from 3.2 upwards.
http://developer.android.com/guide/practices/screens_support.html#support
The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra large screen should go in layout-xlarge/.
Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier
Devices < 3.2 will not use the -sw layouts. To support all API levels you will need to provide layouts using both types of qualifiers.
Check out this post:
http://android-developers.blogspot.co.uk/2011/07/new-tools-for-managing-screen-sizes.html
Previous versions of the platform will ignore any resources using the new resource qualifiers. This, then, is one approach that will work:
res/layout/main_activity.xml # For phones
res/layout-xlarge/main_activity.xml # For pre-3.2 tablets
res/layout-sw600dp/main_activity.xml # For 3.2 and up tablets
I made an extra layout for the S3 (rebel of all layouts) and people said, using a layout-sw320dp is good for the s3. Everything worked, the s3 chose this folder and the layout looks great on the s3.
But when I try to run my app on a 10" tablet, the tablet uses the same folder like the s3 which is totally wrong.
How can I make the sw320dp layout visible only to the s3 or at least how can I make 10" tablets use the xhdpi folders? I already read, that the android system thinks, because sw360 is a "new" type, it's the best. But I don't know how I can avoid that..
Thanks
This is because of higher order of precedence of sw<???>dp qualifier in Android. res-sw<???>dp has got the 2nd highest precedence in the order of qualifiers.
See Configuration qualifier Table. This is the default order in which Android takes the directories in resource folders. So basically whatever folder you provide which have lower precedence, Android wolud not take that. See How Android Finds the Best-matching Resource.
Here sw320dp means devices with at least 320dp of shortest width. Both S3 and 10" tablets come under that. So Android always take that folder for devices which have shortest width of 320dp.
These are some alternatives you can do:
Make layouts like drawable-720dp(10") and drawable-600dp(7") for
tablets. The problem with giving sw<???>dp is that it's been introduced only in API 13 only. So tablets with API < 13. can't use that.
Change the layout for high density phones to layouts with lower
precedence values.
I basically support this method. This way you can give more support
to lower API devices.
I have tried with:
values-mpdi, values-land-mpdi, values-hpdi and values-land-hdpi
which works fine in phone's screens, the problem is that it could happen that a 7" tablet takes the value from values-mdpi and a 10" tablet too, but the result is not the same, I guess because of the screen size (although is the same resolution and similar density)
so I tried:
values-sw600dp-hdpi
values-sw600dp-port-hdpi
values-sw600dp-mdpi
values-sw600dp-port-mdpi
values-sw720dp-hdpi
values-sw720dp-port-hdpi
values-sw720dp-mdpi
values-sw720dp-port-mdpi
but the app crashes because it does not find the resource needed....
any help will be much appreciated
thanks in advance
Basically three main device categories exist that Android applications need to support:
handsets (phones)
small tablets (7″ category)
large tablets (10″ and above).
Qualifiers before Android 3.2:
Google’s first attempt at creating qualifiers to separate resources by device was to create a handful of size buckets: small, normal, large, xlarge. Initially, this worked out well as handset devices were in the small/normal category, the first 7″ tablets on the market were large, and the first 10″ tablets were xlarge.
Qualifiers with Android 3.2 onwards:
However, as more and more devices began appearing in the market with new screen sizes and the lines began to blur about where a device might present itself. A new solution to the problem was presented in Android 3.2, in the form of new qualifiers to pick resources based on a devices current width/height or “smallest” width; the latter being a new designation for the devices size by representing it in terms of the width (in density-independent pixels, or dp) of the shortest side of the screen.
Using the new paradigm, it has become common to define small tablets as having a smallest width of 600dp, and large tablets at 720dp, with handsets being everything that falls below that line.
Using qualifiers when minimum support is below 3.2 and target is higher than or equal to 3.2
For applications targeting Android 3.2 or higher as a minimum this new system works well. However, if developers wishing to create an application that runs universal on handsets and tablets are compelled to support a minimum Android version no higher than 2.2, or at best 2.3, then in that case create duplicates of each resource in a directory with the old size qualifier and place it an another directory with a corresponding smallest width qualifier.
E.g. keeping the same dimens.xml file in values-large and values-sw600dp. So the device running on android version lower than 3.2 will take values from values-large and the device running on android version higher than or equal to 3.2 will take values from values-sw600dp
//you need to run this in API level 3.2 and above.
for the <3.2 you need to declare normal values-large and values-xlarge