Understanding Drawables and Images sizes - android

Firstly I did a lot of search to understand how it work, but I don't find simples tutorials. An exemple, this view:
These are my drawables folders:
The selected device is: Pixel 5.0 1080 x 1920 (xxhdpi).
Immagine in this resolution (1080 x 1920) I set the image view on the top in blue color (Solutis) with 700px of width and 250 px of height, how I have to resize this images for each drawables folders ?
I found this informations:
LDPI - 0.75x
MDPI - Original size // means 1.0x here
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
And
LDPI: Portrait: 200 X 320px
MDPI: Portrait: 320 X 480px
HDPI: Portrait: 480 X 800px
XHDPI: Portrait: 720 X 1280px
XXHDPI: Portrait: 960 X 1600px
XXXHDPI: Portrait: 1440 x 2560px
Here I don't understand why when I select my vistuel device 1080 x 1920px on the Design Edit it say xxhdpi and xxhdpi is 960 X 1600px...
And what gonna be the different sizes of the image for the differents drawables ?
If someone can publish a project exemple, I wool look on, please.

Did you check the documentation? Here is the interesting part:
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
This means if your device as a higher density a bigger image will been chosen.

Related

I can not deal with non-standard resolution

I have design for my project. It for Nexus 6 with resolution 1440px x 2560px and 493 ppi. My design - 1440px x 2560px.
I know that:
ldpi 120 dpi
mdpi 160 dpi
tvdpi 213 dpi
hdpi 240 dpi
xhdpi 320 dpi
xxhdpi 480 dpi
xxxhdpi 640 dpi
I have - 493 ppi. what's this? I have a button size 100x50 pixels on the design.
how many dpi need button to look as well as in the design?
Hope this helps: Getting Your Apps Ready for Nexus 6 and Nexus 9
Nexus 6
Screen
The Nexus 6 boasts an impressive 5.96” Quad HD screen display at a
resolution of 2560 x 1440 (493 ppi). This translates to ~ 730 x 410 dp
(density independent pixels).
Check your assets
It has a quantized density of 560 dpi, which falls in between the
xxhdpi and xxxhdpi primary density buckets. For the Nexus 6, the
platform will scale down xxxhdpi assets, but if those aren’t
available, then it will scale up xxhdpi assets.
EDIT:
Consider this line
2560 x 1440 (493 ppi). This translates to ~ 730 x 410 dp (density
independent pixels)
It implies the scaling factor is 2560/730 = 1440/410 ~ 3.5
For a screen of width 410 and height 730 in dp, if you want to specify a button of half the screen width in dp, the width should be 410/2 = 205 dp which translates to 717px = 205*3.5 (width in dp * scaling factor)
A button of size 100px x 50px would translate to 28 x14 dp (100/3.5 * 50/3.5) on a 410 x 730 dp screen size.
If you are genuinely concerned about proper display resolution (which it sounds like you are) then you should never rely on the generic folders. The folders are there for generalized purposes - not for customized or high value display.
You should use displayMetrics to measure the screen size and select the appropriate asset, or even do customized image scaling. There are a lot of resources around this set of properties, but essentially it allows you to address the issue you are facing: set appropriate margins, padding, resolution, layout, etc. for a highly customized display.
Here are the docs:
http://developer.android.com/reference/android/util/DisplayMetrics.html
And then some "simple" implementations of getting the metrics:
How to get screen display metrics in application class
getting the screen density programmatically in android?

Image resolution for mdpi, hdpi, xhdpi and xxhdpi

I have a background for my app in resolutions 720x1280 pixels, 1080x1920 pixels and 1440x2560 pixels.
In which folders (mdpi, hdpi, xhdpi and xxhdpi) should I put each background?
Please read the Android Documentation regarding screen sizes.
From a base image size, there is a 3:4:6:8:12:16 scaling ratio in drawable size by DPI.
LDPI - 0.75x
MDPI - Original size // means 1.0x here
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
For example, 100x100px image on a MDPI will be the same size of a 200x200px on a XHDPI screen.
Require Screen sizes for splash :
LDPI: Portrait: 200 X 320px
MDPI: Portrait: 320 X 480px
HDPI: Portrait: 480 X 800px
XHDPI: Portrait: 720 X 1280px
XXHDPI: Portrait: 960 X 1600px
XXXHDPI: Portrait: 1440 x 2560px
Require icon Sizes for App :
http://iconhandbook.co.uk/reference/chart/android/
DP size of any device is (actual resolution / density conversion factor).
Density conversion factor for density buckets are as follows:
ldpi: 0.75
mdpi: 1.0 (base density)
hdpi: 1.5
xhdpi: 2.0
xxhdpi: 3.0
xxxhdpi: 4.0
Examples of resolution/density conversion to DP:
ldpi device of 240 X 320 px will be of 320 X 426.66 DP. 240 / 0.75 = 320 dp 320 / 0.75 = 426.66 dp
xxhdpi device of 1080 x 1920 pixels (Samsung S4, S5) will be of 360 X 640 dp. 1080 / 3 = 360 dp 1920 / 3 = 640 dp
This image show more:
For more details about DIP read here.
Check the image above I hope it will help someone.
Link to the whole article itself
Your inputs lack one important information of device dimension.
Suppose now popular phone is 6 inch(the diagonal of the display), you will have following results
DPI: Dots per inch - number of dots(pixels) per segment(line) of 1 inch.
DPI=Diagonal/Device size
Scaling Ratio= Real DPI/160.
160 is basic density (MHDPI)
DP: (Density-independent Pixel)=1/160 inch, think of it as a measurement unit
in order to know the phone resolution simply create a image with label mdpi, hdpi, xhdpi and xxhdpi. put these images in respective folder like mdpi, hdpi, xhdpi and xxhdpi. create a image view in layout and load this image.
the phone will load the respective image from a specific folder. by this you will get the phone resolution or *dpi it is using.

Android image resource and need for 10 images to cater for each screen resolution and orientation

I'm a beginner developing an Android app that needs to display a clip art type png image the full width of the screen in both portrait and landscape mode:
Portrait:
Landscape:
Would I be right in saying that in order to cater for each screen resolution and orientation I need to include the following image sizes?:
Image width: Resource folder:
xxhdpi – 1920 px drawable-land-xxhdpi
xhdpi – 1280 px drawable-land-xhdpi
xxhdpi – 1080 px drawable-xxhdpi
hdpi – 960 px drawable-land-hdpi
xhdpi – 720 px drawable-xhdpi
mdpi – 640 px drawable-land-mdpi
hdpi – 540 px drawable-hdpi
ldpi - 480 px drawable-land-ldpi
mdpi – 360 px drawable-mdpi
ldpi - 270 px drawable-ldpi
This seems overkill. The App could have a thousand of these images and thats 10 versions of each.
What is the normal approach in this scenario?
Would you scale the images to suit?
Assuming you will maintain the same aspect ratio regardless of whether the screen is in portrait or landscape orientation and you will be displaying the image via an ImageView, you will only need 4 versions of each image - xxhdpi, xhdpi, hdpi, and mdpi.
As far as the image widths go, stick with the 2:3:4:6:8 scaling ratio recommended here, in the Android Documentation. That link specifically discusses icons, but the scaling ratio holds true for all images. So if you are using an image width of 640 px in landscape on mdpi, the hdpi, xhdpi, and xxhdpi should have widths of 960 px, 1280 px, 1920 px, and 2650 px, respectively. Don't worry about a ldpi version because Android will scale down the hdpi version for low resolution devices.
Last thing, set the scale type of the ImageView to a scale type which will maintain the image's aspect ratio (CENTER_CROP or CENTER_INSIDE). See the ImageView documentation for info about setting the scale. Then once you set the image to fill up the width of the screen, the image should appear as you would like.

Screen size and dpi of bitmaps

I found two approximations of how developer should support bitmaps for different screen sizes. One is this:
ldpi low density 120 dpi
mdpi medium density 160 dpi
hdpi high density 240 dpi
xhdpi extra high density 320 dpi
The other is this:
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75
This means that if you generate a 200x200 image for xhdpi devices, you
should generate the same resource in 150x150 for hdpi, 100x100 for
mdpi and finally a 75x75 image for ldpi devices
Does it mean that If I take as a baseline 640x360, I have to make following 4 groups of images:
1) ldpi - size 480x270 pixels and density 120 dpi
2) mdpi - size 640x360 pixels and density 160 dpi
3) hdpi - size 960x540 pixels and density 240 dpi
4) xhdpi - size 1280x720 pixels and density 320 dpi
You are misunderstanding.
The documentation is not saying different things. The second part you reference is telling you how much bigger an image is in relation to the base density of mdpi
e.g xhdpi fits 2x the amount of horizontal and vertical pixels into the same space that mdpi would.
mdpi = 160 dpi (scale factor 1)
xhdpi = 320 dpi (x2 twice as dense as mdpi therefore an image in this folder needs to be twice as high and twice as wide as its mdpi counterpart to appear the same size on an xhdpi screen)

Android background image size in pixel

I would like to create a background image for different resolutions in Android. So I need the values (in pixel) for ldpi, mdpi, hdpi,xhdpi and xxhdpi. It is important that the image will not be blurred.
I have already read the Documentation about multiple screen support but there are sizes in dp instead of pixel.
Try follow below android icon graphy size reference for various device screen resolutin.
ldpi mdpi hdpi xhdpi xxhdpi xxxhdpi
Launcher And Home 36*36 48*48 72*72 96*96 144*144 192*192
Action Bar And Tab 24*24 32*32 48*48 64*64 96*96 128*128
Notification 18*18 24*24 36*36 48*48 72*72 96*96
Background 320*426 320*470 480*640 720*1280 1080*1920 1440*2560
there is no full list of screen resolutions, there are no fixed values in pixels for ldpi, mdpi, hdpi,xhdpi and xxhdpi. Every android device may have different resolution. If you want to fill all resolutions you will have to create too many images. If you put them in your app, it will make the app size huge. Maybe a better approach is to use composite image for background.
According to android documentation
mdpi is baseLine size
we can use it to measure all other scales , that mean if mdpi (scale 1) equal 1 xhdpi (scale 2) should equal 2 , multiplay mdpi sizes in scale value
all sizes width x height in pixel
xxxhdpi: 1280x1920 px // 4x
xxhdpi : 960x1440 px // 3x
xhdpi : 640x960 px // 2x
hdpi : 480x800 px // 1.5 x at least 480x720
mdpi : 320x480 px // baseline = 1x
ldpi : 240x360 px // .75 x
** notice I add xxhdpi with 3.0x scale to image*
xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px
i think it is rather easy to convert the DP into pixels in andorid java i am achieving this with this function that i created
int getPixels(Context context, float dp) {
return (int) (context.getResources().getDisplayMetrics().density * dp + .5f);
}
hopefully this is helpful for people,
and kindly do share your views on it, as i would like to get this conversion as accurate as possible, thankyou

Categories

Resources