android resource specifiers - avoiding image duplication - android

I am making a game for android which uses a large number of images.
I have a set of images that I would like to use for 480x800 ish resolutions (i.e. large devices or normal hdpi/xhdpi devices). Another set of images I should like to use for normal mdpi, normal ldpi and small devices of any dpi.
My problem is this. I could copy the images into many different folders which would give me the desired functionality. However, this would make my .apk too large. I could also create resource aliases using xml. However, with the amount of images, I'm looking at having to create hundreds of xml files manually.
Any ideas on how to accomplish the following more conveniently? I noticed they have introduced new resource specifiers that would solve my problem in API level 13, but I need this to work on android 2.1+

There are resource specifiers in android 2.1+ they were just changed to handle different parameters that better suited android becoming both a tablet and phone platform.
The old specifiers were drawable-hdpi, drawable-mdpi, and drawable-ldpi.
drawable-xhdpi was added to support larger screen sizes in Android 2.2.

Related

App Crashes. Error Inflating XML. Cant find image because xxxhdpi folder is not there

Switched my eclipse project to Android studio. I was maintaining resources under drawable-mdpi folder only. Now in studio the preview of XML loads images correctly. However when I run the app in a device with resolution higher than mdpi the app crashes, shows error inflating binary XML.
After a long analysis I found the issue that the device was trying to load images from its corresponding density folder which is not available. So I created the folder drawable-xhdpi and put images in that folder. Now the app works fine.
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
you have to add "drawable-hdpi" resource directory and paste all the hdpi resources there because currently 70% android devices supports hdpi resolution images.
if you only maintain the hdpi, then it is also ok.
android manages all remaining resouces from hdpi resouce directory.
Android application resource directories provide different layout designs for different screen sizes and different drawables. These different drawables are used by android to support a major range of all the android devices present out there. It's a standard practice to put your resources considering these densities. Coming back to your query:
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
For your case,In order to maintain this you could create a drawable with nodpi and put your all resources there. nodpi focus resources for all densities.Your resources should be density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
Hope this will clear your doubts, for more insight you can also look this.
you don't need to add all images to each difference size folder but depending the size of the image you might need to add images to different folders.
simple example is this can occour once you add high res/size images in normal drawble folder
Skipped 100 frames! The application may be doing too much work on its main thread.
This might not crash your app but will make it's performance down.
and
Different density folders were added later on for Android which means that...
If you wanted to be lazy and just add one asset the best choice would probably be the HDPI asset if your min app target < 8 and XHDPI if its >= 8. This is because the system will scale the resource up and down, but you would still want to start off with the highest resolution possible.
If you want to have complete control over how the assets are scaled then you can by all means provide your own for all / some of the densitys. In practise I generally provide HDPI / XHDPI as above and give all the resource buckets for things like logos / AB icons / App icons etc. I generally find the auto scaling to be pretty good and work for most situations, but will occasionally have to supply and extra LD/MD asset if its a small asset / contains small text etc. Plus if i duplicated all assets for things like XXXHDPI I would get pretty good apk bloat.
You can also use IDEs built in tools to add a single asset for many densitys at once. In Android Studio 0.6 this is File->New->Image Asset and a wizard will appear.
I have never noticed or heard of any perfomance impact of allowing Android to scale assets automatically - presumably this is done in hardware.
It may not look great when auto scaling down to LDPI say so you can optionally provide your own scaled assets for all other densities.
taken from : https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
Do we need to add all images with different dpi to Android Apps

Avoid duplicate files in different android drawable folders

I'm developing an android game and will try cover as many different phone and tabled screen sizes and resolutions as possible. To make it easier to handle graphics I've designed some of my icons so that for example a 7" mdpi tablet uses same icons as an xhdpi phone.
That means I have put exactly the same icon file in drawable-xhdpi folder as in drawable-sw600dp-mdpi. I also have same files in drawable-land-xhdpi as in drawable-sw600dp-land-mdpi. It doesn't feel good to have duplicate files, can it be avoided somehow? Or how smart is eclipse compiler, can it detect duplicate files and compress the apk file accordingly?
You can avoid duplicating image files by using aliases. An image alias is an XML resource file containing a <bitmap /> tag. Look at the documentation for the syntax.
In your case I think you should name your resources differently for phone and tablets if they don't end up having the same density-independent size. From what I understand, your tablet images are bigger than your phone images, which is generally not a good idea.

Where to find large stock Android drawables?

Just as the title says. I know there are drawables in android.R.drawables, but because they are so small, they look horrible when scaled up. Does anyone know where I can find the current 4.x drawables that are larger than the ones in the folder?
Since I don't know much about drawables anyways, are the stock drawables in android.R.drawables all in a single size, or are there multiple versions to support different density screens? If so, how can I access these larger drawables?
Does anyone know where I can find the current 4.x drawables that are larger than the ones in the folder?
If you mean larger than the -xhdpi ones, they are probably on some graphic designer's workstation at Google.
are the stock drawables in android.R.drawables all in a single size, or are there multiple versions to support different density screens?
They ship in multiple densities.
If so, how can I access these larger drawables?
They are in your SDK directory, in platforms/$VERSION/data/res/, where $VERSION is one of the available API levels that you have installed.

How to set the drawable to for android app for multiple resolution?

I am developing android app which has lots of images. It's a korean app.
I want to support maximum number of resolution possible.
So I created 4 different folder(ldpi, mdpi, hdpi, xhdpi) for drawable as the google doc stated.
Now my problem is that my app work on all most all device perfectly but In korea there is device Pantech Vega LTE M which is giving lots of trouble
It's resolution is of xhdpi category but still in this device my app shows images from mdpi and it show bigger than it resolution. So half of the image is displays compressed.
So I am not getting how to set the drawables for this device. Do i need to add separate drawable folder to match this resolution.
If i changes the images in mdpi folder than it will create problem for other resolution.
Beside how many folder I need to add make my app compatible with every possible resolution available.
Thats because that device runs Android 2.3 Gingerbread where the X-Large configuration was yet not supported since that resolution was supported beginning with Adroid 3.0 afaik.
Edit:
Looks like the xhdpi was supported since API level 9, and the configuration specs from your device looks like a normal - large screen with xhdpi. So the only workaround that I could think of is creating those folders within your drawables.

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)

Categories

Resources