I'm trying to display an image in an ImageView on 10' lenovo yoga. In each drawable folder I have put an instance of the same image with different sizes:
ldpi: 184 x 294
mdpi: 248 x 397
hdpi: 375 x 600
xhdpi: 496 x 794
xxhdpi: 800 x 1280
The images are the screenshots I've taken with the same device with xxhdpi image being the original image. The problem is instead of loading the image from a high res folder it is loading the image from mdpi and thus the result is blurry. Why is it doing this?
The drawable folders refer to screen density I believe. At http://developer.android.com/guide/practices/screens_support.html it says,
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
I looked up the specs of the 10' lenovo yoga and depending on the one you own, the screen density will be different. For example the Yoga 10 has 149 ppi and the lenovo yoga 2 pro has 276 ppi. So that could be the reason why it's pulling from the lower resolution drawable folders.
Related
My goal is to create One layout that works for different tablet dimensions.
The app will present the information on Landscape mode.
In my case, I have these two tablets to test, they are 7 inches but with different dimensions:
Acer Iconia One 7 B1-770 Model: A5007
Physical Characteristics
Height: 0.4" (9.5 mm)
Width : 4.3" (108.8 mm)
Depth : 7.4" (189 mm)
Weight (Approximate): 280 g
1024 x 600
Samsung Tab 4 7' Model: SM-T230NU
Dimensions: 186.9 x 107.9 x 9 mm (7.36 x 4.25 x 0.35 in)
Resolution: 800 x 1280 pixels (~216 ppi pixel density)
How can I achieve this goal?
Thanks in advance
You have to create Different values folder for different screens in res folder with folder name Like this
values-sw720dp 10.1” tablet 1280x800 mdpi
values-sw600dp 7.0” tablet 1024x600 mdpi
values-sw480dp 5.4” 480x854 mdpi
values-sw480dp 5.1” 480x800 mdpi
values-xhdpi 4.7” 1280x720 xhdpi
values-xhdpi 4.65” 720x1280 xhdpi
values-hdpi 4.0” 480x800 hdpi
values-hdpi 3.7” 480x854 hdpi
values-mdpi 3.2” 320x480 mdpi
values-ldpi 3.4” 240x432 ldpi
values-ldpi 3.3” 240x400 ldpi
values-ldpi 2.7” 240x320 ldpi
Create layout-sw600dp-land folder with xml file for desired layout.
Add this attribute to your AndroidManifest file.
<supports-screens
android:largeScreens="true"/> //for tablets 7'
I know we have some standard of DPI that we can use it for support multiple screen size in an like :
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
But when I calculate for some real device, e.g. LG G3 - it has DPI is 538.
So my question is do we need to use that exactly DPI number for scale the image,... or just let it be one of xxhdpi (480dpi) or xxxhdpi (640dpi).
For my opinion, I think you shouldn't care about information dpi of devices. You should only focus to provide images, size (dp,sp) etc for some type of screens :
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
=========================================================================
Example:
As you maybe known that 1 px = dp (dpi/160)
So if you have an image with size is 32 x 32 px on screen 160 dpi. It's mean your image get size 32 x 32 dp.
Now you want to scale it on xxhdpi (extra-extra-high) ~480dpi.
On xxhdpi (extra-extra-high) ~480dpi : 1 px = dp(480/160) = 3dp
Then you only need to provide another image with size 32*3 x 32*3 px = 96 x 96 px
You just have to provide the right assets and android will take care of the rest. You can check the documentation for more details.
The Android system helps your application achieve density independence in two ways:
The system scales dp units as appropriate for the current screen density
The system scales drawable resources to the appropriate size, based on the current screen density, if necessary
So in your case its better to provide both the assets. At runtime, the system uses the appropriate resources for your application, based on the generalized size or density of the current device screen.
I am using a 100x100 pixel image to display something on the only device I support, the 3.2" 240x320 pixel LG E430. I found some strange behaviour though. If I put that image in the drawable-ldpi folder, it will be rendered larger than when I put it in my drawable folder.
Is this intended? And if so, how should I scale my images so they get rendered correctly, but still can reside in the drawable-ldpi folder?
putting image in drawable folder should be treated as drawable-mdpi, that's why if you put your image in drawable-ldpi it would be larger.
Edit:
In order to put the image in drawable-ldpi and having the same size as it was put in drawable, scale the original image from 100 x 100 to 75 x 75.
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
i just wanted to know. i've read about this DPIs and i wandered all of the varieties. since i am new to this, i need some knowledge and i hope someone can help me out. so far i've seen LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI.
is there any other DPI variety other than this. and what is their respective resolutions ?. like as for qHD = 960 x 540 etc etc. i hope you understand guys, thanks.
please forgive me if my grammar is a little crappy, as english is not my native language
Android supports different screen resolutions
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
1 dpi = 1 design independent pixel
ldpi device have 120 pixels in 1 inch size.
same for other densities...
we as programmer should use this conversion formulae :
pixel = dp * (density / 160)
so 240 dpi hdpi device's 1 dp will have = 1 * (240/160) = 3/2 = 1.5 pixels
and 240 dpi xxhdpi device's 1 dp will have = 1 * (480/160) = 3 pixels
Using this 1.5 and 3 pixels knowledge, programmer can design layouts for different densities
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.