Setting background image in Android for mdpi, ldpi, hdpi - android

I'm working on setting background image sized 320X480 jpg, for >= android 2.2 versions.
As per my understanding from previous posts related to mdpi,ldpi,hdpi & info from http://developer.android.com/guide/practices/screens_support.html , we can use image sized to
ldpi, the recommended size is 240x320.
mdpi, the recommended size is 320x480.
hdpi, the recommended size is 480x800
My question is, will the above mentioned sized images (in jpg format) work (or) should i have to create a single image generated using 9 patch placed in drawable/
and also i'm little confused in using jpg format for background, as i have seen many sample programs referring to png format, is that a standard or can we use any format ?
Any help would be really appreciated.
Thanks - Jitendar

The screensize doesn't have to be the ones you mentioned - it can be any other. Therefore better use a ninepatch to stretch the image properly. You should still provide different versions of those though, especially if you have parts of the image that don't stretch.

You can use either jpg or png...it does not matter...As for backroung image you can use an image that will have all sizes...just put it in corect folders and you will not have any problems...

Related

Can we use images in one image density without any quality lost? (Android Image Density)

I work on an image sequence animation. I have 75 png files. I want to use images in one size without adding mdpi, hdpi, xhdpi etc types and get the same view on all devices. Is there a way to do this?
Best,
You Can try the following way may help you
(1)use only mipmap-xhdpi folder and create image according to mipmap-xhdpi density requireda and put all in xhdpi.
(2)Use Vector Drawable/Vector Graphic features in Android studio....Please read detail from https://developer.android.com/training/multiscreen/screendensities
(3)Please try to create the nine-patch image...Please read from https://developer.android.com/guide/topics/graphics/drawables#nine-patch.
https://developer.android.com/studio/write/draw9patch

Detemine correct image size to use for nodpi

I had different nine-patch images for different screens. However, I encountered an issue
android drawable image takes lot of memory compared to its disk size
So, I decided to use, for now, nodpi with hdpi image size.
Since, I have limited understanding, I was wondering what should be the image size I should put in drawable-nodpi folder.
Should I put hdpi images or xxxhdpi images? Or something else?
Please help me understand.

Android Appropriate Image Resolution for ImageView

What is the proper/right resolution for Image to be put using src in ImageView to avoid stretching or unscaled images?
if you are using a single color of background, u can use 9Patch images. but if you are asking about icons then you need different images for different resolutions in drawable folders like drawable-hdpi for hdpi devices drawable-xxhdpi for xxhdpi devices.
for more detailshttp://developer.android.com/training/basics/supporting-devices/screens.html
To understand the image size check out the following link image size (drawable-hdpi/ldpi/mdpi/xhdpi) . To avoid stretching use "android:scaleType="fitcenter/fitxy/centercrop"" for more detail check this http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Actually it totally depends on your placeholder or your needs, rather than single image you can make different sizes of image for different dp like small,large,normal,x-large .
probably https://romannurik.github.io/AndroidAssetStudio will save your time or new Android studio 2's built in plugin.
More resource
http://developer.android.com/training/basics/supporting-devices/screens.html

What is best way to create drawable asset?

If I put my application resources in drawable-xdpi then it is automatically down converted for hdpi, mdpi and ldpi by ration 0.75, 0.05 and so on.
Why we need to create extra resource if one type is enough only?
I believe it is enough if I create for xhdpi and let Android down scales automatically. I have gone through this question
What is the best way to create drawables for different dpi
but no one has given answer that yes you can go this way.
Suppose I kept my images in xhdpi and when app opens in hdpi it will reduce size to 0.75, when it opens in mdpi it reduces size to 0.5.
So what is best way to create draw able asset? Please suggest perfect way with valid reason.
If not needed why we are creating so many resources instead for one only like xdpi?
There are two reasons to provide more than one image:
it is more efficient to load an image that is already the correct size.
The automatic downscaling may produce artifacts, which can be disturbing especially for small images. So if you want a pixel perfect image it is better to provide one in the correct size.
If none of them is a problem for you, it is also fine to go just with one image.
If u want to display same image with different resolutions in devices
xhdpi image then place it drawable-xhdpi
hdpi image then place it in drawable-hdpi**
or to maintain a drawable folder place all the images what you want to display it will display with same size in all devices irrespective of the resolution.

How to use 9 patch images in android for different-2 densities(like mdpi,ldpi,hdpi).?

I am creating an android application in which I want multiple screen support.For these I have used 9 patch images.
But my question is this whether using 9 patch images will be enough for different-2 density's devices or I will need to create different-2 9 patch images for varying densities(like mdpi,ldpi,hdpi).
Thanks in advance
I recently found out myself in the same situation so let me pitch in and expand on what has been said already...
Yes, 9-patch images will scale, that's what they exist for. But if you should use a 9-patch image for all screen densities, that depends on the image really. 9-patch images are more commonly used, for instance, buttons. You can have different sized buttons in your app and a 9-patch image will help deal with them, no matter how you size your button (as long as the 9-patch image is properly created).
But let's say your button design has some really round corners for the hdpi version. You create your 9-patch image without messing the corners but when you look at it in the ldpi version, you'll realize your corners are too big for that low resolution. For this situation, you'll need a different 9-patch image with less round corners, that look better on that resolution.
So, the final answer is, it really depends on your image. If you can create a 9-patch image that looks good in all densities, than fine, use it, as you only need one image to handle all densities. But if it doesn't look good, because of corners, gradients, or whatever, than you'll need one 9-patch image for each screen density.
Hopefully it's clearer now.
From documentation: nine patch
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background. An example use of a NinePatch is the backgrounds used by standard Android buttons — buttons must stretch to accommodate strings of various lengths. A NinePatch drawable is a standard PNG image that includes an extra 1-pixel-wide border. It must be saved with the extension .9.png, and saved into the res/drawable/ directory of your project.
the answer is no. you nine patch will scale between different screen size
Short answer is YES.
Check this:
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate
physical size on each device. For example, if your application provides bitmap drawables only for
the baseline, medium screen density (mdpi), then the system scales them up when on a high-density
screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the
bitmaps. To ensure your bitmaps look their best, you should include alternative versions at
different resolutions for different screen densities.
from Android Developer Official Doc

Categories

Resources