Android SDK - selecting correct resources - android

I built an Android tablet application and I'm trying to figure out how to make the system select the correct resources.
I understand the concepts described in the documentation. There are a number of different resource folders for different densities ldpi, mdpi, hdpi, etc... - but is there a way to have the system select resources based on resolution of the device? In the layout folder structure you can specify minimum width with layout-sw600dp. Is there a similar mechanism for resources? There are several devices considered medium density that have different resolutions. Ideally I would like to define resources for resolutions and have more flexibility than just pixel density.
I've also tried to use the built in scaling but it doesn't appear to work with my Nexus 7. Resources that are designed for higher resolutions do not seem to scale down at all. Perhaps I'm doing something wrong.
Thanks.

I'm not 100% sure I read your question correctly, but you can suffix any subfolder of the res/ folder with the target specifiers. So not just res/layout-sw600dp, but also res/drawable-sw600dp and res/values-sw600dp. These rules can be combined, so res/values-sw600dp-mdpi will also work.
Also note that the Android SDK Documentation is a bit flaky in this area. The Training section explains a neat trick using resource aliases that helps you avoid copy-pasting layout XML's, but the API Guide and Reference docs never mention it, so it's easily overlooked.

you can, you can specialize folder name like this, drawable-800x480, but make sure that greater value will become first(800 in this case)

Related

Supporting different devices with different layout

I have doubt in making the layout for other deices I mean to support different devices of different resolutions. I have made an application and it is working well on hdpi devices and I tested on Samsung Galaxy grand which has 320dp-460dp and 480px-800px.
May application is looking awesome on this device. but when I run on other devices its gone bad. SO I am suggested to make the folder like layout-large, layout-xlarge and layout-xxlarge but there is a lot of difference in this link and this link
So this makes me confuse , with which name I have to make the layout folders to support all devices ?? please tell me
and also tell me I have some hard coded values in my layout such as left margin 13 dp to make my design look perfect on hdpi device should I make it more in other xhdpi devices ???
and also which devices comes in layout-large folder and so on please answer my both confusion , thanks in advance
I use Google's code as an example of how to do stuff. The docs on "Supporting multiple screen" is a bit old and outdated. The best way to keep up with the current conventions is to follow other's codes.
Here is the source code for the Calendar app. Yes, there a lot of different folders for layouts/drawable/values but you have to consider the fact that there are a lot of devices with varying sizes and pixel densities.
Also, why do you want to make many folders for layout? You make a few layouts and let the values and drawables do the rest of the work. Hope it's helpful.
IF you are interested in knowing which device falls under which folder, then check this figure from the Official Android Guide:
Of course you need to know the actual size or density of the physical device

Inflate from layout-v10 folder on a hdpi gingerbread device?

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.

Android muliple screen support?

I have to design an application which to support under three resolution. for that i use the code in manifest
and also create three folder layout , layout-large, layout-small for supporting three resolution, correspondingly i put the different resolution of image in drawable-hdpi ,drawable-ldpi ,drawable-mdpi , but whenever i run the app in different resolution it going to take low resolution image instead of different resolution i use.
I don`t know where i made the mistake, whether i have to add some code in layout xml or not. I also search the android developer forum and i do the application design as they insist.
Any one suggest some idea to achieve this.Thanks
There are two things you could check: have you set the minimum SDK version of your app to use version 4 (Android 1.6) support for this started?
Secondly, the layout-large and layout-small folders are designed for different sized screens (think tablet vs phone), and not resolution. If you're changing the resolution (DPI) of the device, you'll need to use layout-hdpi, layout-ldpi etc.
Further, if it's only the images you're changing, you should be placing the different images in drawable-hdpi, drawable-ldpi etc, and not layout-xxxx. If on a supported device, Android will pick the image from the correct folder, so you'll only have one layout folder (or 2 if you use layout-land)
Some (or all :S) of these points are covered in this link, to another question on StackOverflow. Try to use the search function before asking a question. Also, you'll find people are more receptive to providing answers to users with higher accept percentages.
Android - layout-large folder is been ignored
Edit: for multiple screen support, also look at Fragments to better organise and fit your content for both large and small screen devices (dev.Android, worked example)

Publishing multiple versions of one app on Google Market

I have an Android app that I would like to display high quality images with. However there are many different screen sizes and ratios. I know there are filters to show apps in Market only for devices with small/medium/large screens.
If I put images of both sizes in 1 app it will double the size of the app, right?
Is it a good practice to make multiple versions for different screen sizes?
I would like to make 1 app in 3 versions for such devices:
medium screen mdpi
medium screen hdpi + large screen mdpi
large (tablets)
If it's possible to do it how can I specify them in manifests? Or is it somewhere in market?
Android has a built-in mechanism for having resources designed for different screen sizes and pixel densities. It's called resource directory qualifiers, and you can read all about it here.
For example, for small screen sizes, you could create a specific layout file and place it in the res/layout-small directory. For a larger screen, you could create a layout file with the same name and place it in the res/layout-large (or res/layout-xlarge) directory.
For pixel density, you could create a small version of your image resources and place them in the res/drawable-ldpi directory (lower pixel densities). And for higher pixel densities, you could create alternate versions and place them in the res/drawable-hdpi directory.
I'd encourage you to read the page on Supporting Multiple Screens, and let Android help you out with its built-in mechanisms. Creating three separate copies of your app is harder for you to maintain, and it confuses potential users (most of whom probably neither know nor care about "pixel densities"). What's to stop them from downloading the wrong version of your app, and getting a lousy experience because of it?
No one seems to be addressing the file size issue you're really asking about, so I'll try.
You should package your high quality images as a set of separate downloads, one for each type of device you plan to support. This makes your base app small, and ensures the end user's disk space is only filled by images it needs.
I've not done this myself, but hopefully the idea will send you on the right search path. I imagine you design the separate download as either resources on your own server, or another set of apps in the market (i.e. "MyApp Image Pack HDPI", "... MDPI", etc.).
As Donut mentions above android has excellent documentation for this here, here, here and here.
Note that all Manifest file changes and how to create one binary that will support different screen sizes, different densities AND different SDK's are at android website. But it requires careful planning and testing to do so.
The best way is to have ALL device configurations (listed here, including the Samsung Galaxy Tab simulater (large screen, hdpi) available here) in your development environment and test your app on them.
You have to create different .apk for each version and define this in your application's manifest file.use this link
http://developer.android.com/guide/practices/screens-distribution.html

Android Screen Density Compatibility on 1.5

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

Categories

Resources