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
Related
I use API 7. I know there are two ways for my question:
1- using the layout-small and layout-normal and layout-large and layout-xlarge.
2- using the sw-320dpi and like this.
When I see the all existing devices (tablet and phones) in the android studio, I understand it does not contain the all existing devices (tablet and phones) in marketplaces. Now I want know your experience about my question. If you want create an application that it uses the API 7, Which method you choose? I do not want link from other websites, I want know your experience about supporting different screens? What is the best way?
you use api level 7 so you should use :
layout-small, layout-normal, layout-large and layout-xlarge.
because using sw-320dp ... begins with android 3.2(api level 13)
Take a look :
Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier to define the smallest available width required by your layout resources. For example, if your multi-pane tablet layout requires at least 600dp of screen width, you should place it in layout-sw600dp/. Using the new techniques for declaring layout resources is discussed further in the section about Declaring Tablet Layouts for Android 3.2.
http://developer.android.com/guide/practices/screens_support.html
It's not sw320dpi, but sw320dp. This number doesn't represent screen density, but size in the same manner as small/normal etc.
See http://developer.android.com/guide/practices/screens_support.html
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
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.
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.
My app has different layouts and styles for xlarge screens. This is important because on phones it is only used in portrait and on tablets it is only used in landscape.
A user contacted me a few days ago because since I published the update with the tablets layouts he can't see some of the objects in my main activity (prior to this update I only had portrait layouts - also on tablets). He uses a 7 inch tablet running Android 2.3.3 and for some odd reason it is using the layouts and styles from the xlarge directories even thew it should use the default layouts and styles.
I tested it on the emulator and had the same problem. I then changed only the android version to 3.1 (did not change width, height and density) and it worked as expected - the default layouts were used.
I don't want to use version qualifiers (layout-xlarge-v13) because then users with old android versions that have an xlarge screen will get the wrong layouts. For android 3.2 and up I could use sw720dp but older versions will not use this so problem remains.
I am able to tell at run time that the device is not large enough for the xlarge layouts but what can I do in that situation? Is there a way to make it use the default resources?
Android doesn't give its blessing to any 7-inch tablets running Gingerbread or below since Honeycomb was released. This means your device must be either old, or non-CTS compliant. You are looking at an extremely small pool of devices that are: API level 7-10 (roughly), 7-10 inches in size, that live outside the main Android ecosystem.
If you want to support such devices, I would recommend that you make layout-large-v7 and layout-large-v11. Assume that these nonstandard tablets will select the first one, and design for low- or medium-density 1024x600-pixel displays.
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