GIVEN:
Starting with API Level 13 (Android 3.2), the screen sizes (small,normal,large,xlarge) are deprecated in favor of using the swdp qualifier. It is strongly recommended that applications that are meant to run on Android 3.2 or higher should be using these newer qualifiers. http://developer.android.com/guide/practices/screens_support.html
THEN:
What is the best practice for maintaining compatability with api 7+ without making the problem even more complicated by using BOTH techniques at the same time?
To clarify: When creating resource folders for alternate layouts, dimensions,values, etc, with the requirement of supporting api 7+, should we use the deprecated qualifiers (small, normal, large, xlarge) or the new qualifiers (sw600dp, sw800dp etc) or both at the same time?
update:
I just found a similar question where the accepted answer suggested using ONLY the older Abstract Size Bin qualifiers:
https://stackoverflow.com/a/15113877
Use layout aliases.
Quotation from the official documentation:
"The smallest-width qualifier is available only on Android 3.2 and above. Therefore, you should also still use the abstract size bins (small, normal, large and xlarge) to be compatible with earlier versions."
Here is the link for more information - Use Layout Aliases
Related
I'm working in Android Studio, this app is aiming to target devices from API 10, several features I am using for supporting old and new devices I am getting from appcompat library.
When I test in my phone, the app design seems Ok, but I know I have to mantain compatibility for other devices, like tablets. Untill now, I only have created folders in drawable, for different screen densities (mdpi, ldpi, xhdpi...).
The point is how can I support different sizes (i.e. one layout for small phones, other for tablets...). I heard about create folders in layout like small, medium and large, but in Google developers site, this is not recommended, I should use intead sw...dp, however it seems is supported only for api 13 and above.
I am considering make an app for phones and other for tablets, unless there is something I can do, keeping support for api 10 and above and supporting different screen sizes.
As you said, in the android documentation you can find (http://developer.android.com/intl/es/guide/practices/screens_support.html):
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.
It tells you to not use them just if you are designing for API 13 and above. If you don't then you should use the deprecated identifiers.
I don't think make an app for an API lower than 15 has much sense, here you can see some charts of API distribution:
http://developer.android.com/intl/es/about/dashboards/index.html
With API 15 you are covering the 96.4% of the users.
My app has one layout for smartphone and one for tablets.
I want to use the same layout for both large and xlarge devices.
I want to support devices that use API 10 and up, so using sw<N>dp is out of the question.
How can I do that without putting the same xml file in both folders. I don't want to make code duplication. That's against any decent programming principles. :)
I think that a xlarge device would use a "large" resource if there's no xlarge option in the application.
http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch
So you can use only one XML to support either large or xlarge devices.
I'm developing an app whose target SDK is version 8. Despite that, it must work in newer SDKs (Android 4.x, for example).
This site says:
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 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.
What is the best practice in my case? I do know how to handle SDK differences/deprecation when it is about code (verify in runtime what OS version is running). But I don't know how to handle resources in this case.
Should I keep the old standard and use layout-{small,normal,large,xlarge} even with build target >= 13?
Should I change both targetSdkVersion and the project build target to something equal or greater than 13, keep minSdkVersion equals to 8 and use layout-sw<N>dp?
Here is an interesting answer:
Android resource size qualifier
which leads to http://developer.android.com/guide/topics/resources/providing-resources.html
where there is stated that layout-swdp was added on Android API level 13 (Android 3.2) so it's up to you whether you support lower versions, in this case you'll keep using layout-{small,normal,large,xlarge}.
So my answer is, go to the new standard in your case.
Here are general statistics to help you target your minimum version but you may look for more precise stats (limited to a country etc): http://developer.android.com/about/dashboards/index.html
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.
I'm getting ready to release my first application the marketplace. It's being written for devices running Android 1.5 and above, however there aren't any specific folders for the three different screen densities (I think those came around in 1.6). Should I make these folders myself? Where should I put image resources for the different densities and what should I put in my Manifest??
You will actually want to set your application up to target Android 1.6 in order to get the folders with different drawable levels, but then set the minSdkVersion="3" in the XML and rename the drawable-mdpi folder to just drawable. It will give you a warning about version mismatch but this is how supporting 1.5 but getting the nice features of 1.6 is done in Replica Island for example, which was made by a Google developer advocate. One thing to keep in mind is that by targeting 1.6 instead of 1.5, you can add targetSdkVersion="4", so that it will not force all screens to emulate 320 width, but then you will need to be far more aware of how the app will actually look and test it more thoroughly.
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
For more information, read http://developer.android.com/guide/practices/screens_support.html, especially about halfway through where it mentions the XML settings.
There are a number of bugs in the system that need to be worked around as well.
The best strategy I've found to use is:
res
drawable
drawable-hdpi-v4
drawable-ldpi-v4
layout
layout-hdpi-v4
layout-ldpi-v4