2

I know there is a lot of stuff related to how does android store images. and what does mhdpi xhdmi lhdpi etc means But my question is a bit different. actually i am working on a screen whose height and weight in px is 720*1020 px. this is not complete HD, this is sort of SD screen. now i designed images for 720*1080 px with size equal to 520*370 px this is the image size. and i have stored the image in xhdmi

The Issue is

When i put the image on screen and give it

android:layout_height = "wrap_content"
android:layout_width = "wrap_content"

the image is displayed on the screen but it shrinks a to half the original size, so i tried giving the height and width equal to 520px and 370px respectively to the layout then i get the original size of image

My question is:

What size should my image contain so that if i wrap content the height and weight, it gets the original size.

Hassaan Rabbani
  • 2,449
  • 5
  • 28
  • 53

2 Answers2

3

px is one pixel.

sp is scale-independent pixels.

dip is Density-independent pixels. You would use

sp for font sizes dip for everything else.

dip==dp

from here

px Pixels - corresponds to actual pixels on the screen.

in Inches - based on the physical size of the screen.

mm Millimeters - based on the physical size of the screen.

pt Points - 1/72 of an inch based on the physical size of the screen.

dp *Density-independent Pixels* - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

sp *Scale-independent Pixels* - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

will elaborate more on how exactly does dp convert to px:

If running on hdpi device 150x150 px image will take up 100*100 dp of screen space.

If running on mdpi device 150x150 px image will take up 150*150 dp of screen space.

If running on xhdpi device 150x150 px image will take up 75*75 dp of screen space.

The other way around: say, you want to add an image to your application and you need it to fill 100*100 dp control,

you'll need to create different size images for supported screen sizes:

100*100 px image for mdpi

150*150 px image for hdpi

200*200 px image for xhdpi

Digvesh Patel
  • 6,518
  • 1
  • 19
  • 34
  • 1
    please suggest me a solution, say i need to deploy the same application on a HD screen then the sizes will be different, if i use the px size it will be reduced in HD screen. – Hassaan Rabbani Jan 29 '14 at 14:20
-1

In your case the image is resized based on the screen density of the display. Because you placed the image in a higher density folder than your phone is using it will be downscaled. The forth response from How to resize the bitmap image according to mdpi,hdpi and screen size of the mobile explains how the images scale depending on screen density.

You can consider the density on your device, the size you expect to be and increase the size with a multiplier so you can save it in xhdpi folder.

Community
  • 1
  • 1
azertiti
  • 3,110
  • 16
  • 19
  • Any reason for the negative vote? I agree the accepted answer has more information but that doesn't make this one incorrect. – azertiti Feb 04 '14 at 10:25