Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About Android image and asset sizes

I need to clarify some doubt about the image assets for my app,

if I specify in an xml file that the height of something [image view] is 50 dip height

which type of screen should i choose from the resources folder?

drawable, hdpi, ldpi, mdpi, xhdpi, 

to have the 50 px height image,

and what is the percentage for bigger, smaller size images compared to the base image,

like in iOS, @2x, is literally 2 times the size of the image, and you say programatically the normal size,

thanks!

like image 815
manuelBetancurt Avatar asked Jul 20 '12 14:07

manuelBetancurt


People also ask

What is the best image size for Android?

The best image resolution for most smartphones is 640 by 320 pixels, although you should ideally maintain the aspect ratio of the original image or the output image will be distorted.

What are Android assets?

Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data.

What is an android image?

android.media.Image. A single complete image buffer to use with a media source such as a MediaCodec or a CameraDevice . This class allows for efficient direct application access to the pixel data of the Image through one or more ByteBuffers .

What is image asset in Android Studio?

Android Studio includes a tool called Image Asset Studio that helps you generate your own app icons from material icons, custom images, and text strings. It generates a set of icons at the appropriate resolution for each pixel density that your app supports.


1 Answers

mdpi is the reference density -- that is, 1 px on an mdpi display is equal to 1 dip. The ratio for asset scaling is:

ldpi | mdpi | tvdpi | hdpi | xhdpi | xxhdpi | xxxhdpi 0.75 | 1    | 1.33  | 1.5  | 2     | 3      | 4 

Although you don't really need to worry about tvdpi unless you're developing specifically for Google TV or the original Nexus 7 -- but even Google recommends simply using hdpi assets.

What this means is if you're doing a 48dip image and plan to support up to xxhdpi resolution, you should start with a 144px image (192px if you want native assets for xxxhdpi) and make the following images for the densities:

ldpi    | mdpi    | tvdpi    | hdpi    | xhdpi     | xxhdpi    | xxxhdpi 36 x 36 | 48 x 48 | 64 x 64  | 72 x 72 | 96 x 96   | 144 x 144 | 192 x 192 

And these should display at roughly the same size on any device, provided you've placed these in density-specific folders (e.g. drawable-xhdpi, drawable-hdpi, etc.)

For reference, the pixel densities for these are:

ldpi  | mdpi  | tvdpi  | hdpi  | xhdpi  | xxhdpi  | xxxhdpi 120   | 160   | 213    | 240   | 320    | 480     | 640 
like image 141
Kevin Coppock Avatar answered Sep 20 '22 14:09

Kevin Coppock