selecting image from specific drawable folder in android - android

I have a Gallery widget that allows a user to select from a variety of images which I supply with the app. Because of different screen resolutions, I have different size images in different drawable folders. Eg drawable-large has 1280x800 versions of the images, drawable normal has 480x320. This is so the image looks good once selected on all resolutions.
The problem I am having is that the Gallery widget, on large resolutions, ends up using the 1280x800 versions of the images to populate the widget. With around 6 of these images, the VM heap memory becomes too large and the app stops working.
Is there any way to force loading images from a specific drawable folder?
I know I could easily solve the problem by adding extra images to my folders but I don't want to increase the size of my app too much.

You can create aliases to your resources, see http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources
You can then put all your gallery image that are used by multiple resolution in one place, so as to not have resource duplicate in your folders.

Related

How does Android Studio handle image sizes?

I have an application where I use background images.
I don´t want my images to be stretched or deformed when I run my application on different screens with different ratios.
I already have different images for different screen sizes.
Can someone please explain to me how Android Studio handles the image sizes.
How can I make it that the image isn´t streched, but a sector that fits the screen is being displayed?
Android System uses resource qualifiers/filters to load different resources based on current screen configuration.
Now you have different images for different screen sizes, Good!!
the Folder structure would be something like this.
res
-drawable-mdpi
-drawable-hdpi
-drawable-xhdpi
-drawable-xxhdpi
Now when you run your Application on a device with mdpi screen, android loads images which are under drawable-mdpi folder, and when you run your application on a device with screen density of xhdpi android loads images from drawable-xhdpi folder.
Instead of setting the image as a background for my layout I created an image view. There I set the scale Type to centerCrop and it had the wanted effect!

background image with multi screen

I have different folders with different background images for every screen size, also i have created folders for the layouts, the content in each folder is copy & paste (the layout ones) cause i want it to look the same but take the matching pictures for the density.
I don't know why but the application looks great on my phone and very bad on my tablet (background pictures are blurred)

Resource folder selection not working as expected

I've a large image logo I'm currently scaling (usually down) to fill 50% of screen. At first I placed it in the base /res/drawable folder. It worked fine for most devices, but on some low-end phones with small screens the scaling introduced aliasing and it looks horrible. So I distributed the images as follows:
/res/drawable
-Large image, intended to be used on most devices
/res/drawable-normal
-Smaller image, intended to target smaller screens
However, when testing on Samsung Galaxy Tab 2 10' it picks the image in normal folder instead of the image in the base drawable folder. I know this tablet fits in the drawable-xlarge category since it is picking other resources from there. So I had to come up with this directory structure for the thing to work:
/res/drawable
-Large image, intended to be used on most devices
/res/drawable-normal
-Smaller image, intended to target smaller screens
/res/drawable-xlarge
-Same image as the drawable base folder, only used for the tablet to select the correct image.
Now it works as I want, but I can't understand why the system selects the normal folder for an xlarge device. Shouldn't it look first in the xlarge folder and then fallback on the base drawable folder?
Thanks in advance.
It falls back in a scaleable manner.
If it can't find Xlarge, then large is a closer match then normal is a closer match then the default folder
Reference:
How Android finds best matching resources
Android.Developer

Android: Different image based upon screen size

Is there a way to have Android select a different image based upon the screen size? According to the docs and my testing, images must be placed in folders like drawable, drawable-mdpi, drawable-hdpi, etc.
These folders however relate to the screen dpi and not the screen size. The layout folders are used to handle different screen sizes but they don't allow you to store images in them. Only xml files.
So if I run my app on two devices with the same dpi but with different screen sizes, the same image gets selected from the same drawable folder. What I really want is for a larger image to be selected for the larger screen and a smaller image for a smaller screen.
Thanks for your help.
Yea, you are right, this is how works Android, by saving different pictures in particular folders (l,m,h and xh -dpi).
Where is your problem?
You want to keep images for all screen resolutions? Its too many of them.
Can you write more specific what you want achieve?
If you have a problem in layouts.xml, just check:
android:scaleType="..."
You can use 9-patch images. A 9-patch image can be stretched without loosing quality. You may refer to the following link for more information http://developer.android.com/guide/developing/tools/draw9patch.html

in which folder put image for setting to background of layout android

i am putting the image in three of the drawable,drawable-hdpi and drawable-ldpi for supporting all type of screen but when i see the output of background image in 240*320 screen resolution the background image is not as clear as origional so my question is where to, means in which folder i put the background image for supporting it all type of screen size and density, maens then my image should not distorted or bluer...
i am using the background image of size:320*480
thanks
make one folder name
drawable-nodpi
put your image in that and use it and dont keep that image in other folders.
the image will not be scaled or stretched.
Anoher Way
the best way is to make 3 different size images and put int drawable-ldpi(240X320),drawable-mdpi(320X480),drawable-hdpi(480X800) folder with the same name.
TO LEARN MORE PLEASE VISIT THIS LINK.
Supporting Multiple SCreens
You can put different same image in drawable-hdpi,mdpi and ldpi.Depending on the density of devices they will take the images from the corresponding folder.
With different devices you should have same image but with different size and density.for You can search in internet the specifications of devices.If density is less than 160 then put image in ldpi,if 160 then use mdpi and if 240 or above use hdpi.Also change the size of image to the screen size of corresponding device.Hope it will help.

Categories

Resources