How does Android Studio handle image sizes? - android

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!

Related

Android Development - Resizing images into drawable folders

Is there a way to get Eclipse to automatically re-size images and put them in the appropriate drawable folders? When you add an image for the icon when you first create an Android project, it automatically re-sizes the icon and puts them in the appropriate folders. I know you're meant to scale images using a 3:4:6:8 scaling ratio (http://developer.android.com/guide/practices/screens_support.html). I'm wondering if there is a way that Eclipse does this automatically for images?
For re-size icons, right click select New/Other… or press Ctrl+N, select Android Icon Set, the default name for icons is ic_launcher, click Next, in Foreground select Image and Browser that image like to put as icon and is re-sized automatically
Is there a way to get Eclipse to automatically re-size images and put
them in the appropriate drawable folders?
NO, until now, you have to create your own resources defined for every "Screen Density", tools like android_img_resizer will work but can´t support all densities, what if you need resources with mhdpi or tvdpi density.
More info:
Supporting Multiple Screens - Using configuration qualifiers
Designing alternative layouts and drawables
Supporting Different Densities
For re-sizing the images in bulk i will recommend you this tool https://github.com/bearstouch/android_img_resizer . its easy to install and it support the new resolutions (xxxhdpi,xxhdpi) as the base image.Check it out.

Android, my app looks good on vertical screens, but size is all distorted on tablets (wide screen)

When my android app gets drawn on a tablet or a emulator that has a wide screen (wasvga,wxcage800 and my tablet) it draws the graphic images from the drawblw-ldpi folder (low res) instead of the drawl-hdpi folder. I'm curtly using a bitmap button. They are all very small (since the smallest image is being drawn) on the tables, but the correct image gets drawn on all the vertical screens.
Why is this????
Is there a way to fix it????
The default folder is the mdpi folder. If another folder doesn't exist, or doesn't have your image, android gets it from drawable-mdpi. Put your images there, and let us know if it works.

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

selecting image from specific drawable folder in 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.

Setting correct resolution for Background image

I want to set a background image into my app. I tried to set my background image in my xml file with android:background(im using a relative layout) but it seems the image was scaled and doesn't appear to be correct or in its original form.
Let's take an example if I want to display it on a 480x800 screen and only on portrait mode. Should I also produce a background image with a resolution of 480x800?
Thanks
Yes you should. Keep in mind that there are three different directories to put your drawables in (ldpi, mdpi and hdpi drawables directories) put your background images in the appropriate directory according to pixel density and the app will chose the appropriate one to use according to the device it is run on.

Categories

Resources