Let's say I have an ImageButton in my app. The size of the .png for ImageButton is 50x50px and it was originally designed for xhdpi. Let's say I now want to adjust this .png image for other screen densities. Is there some kind of formula that helps you calculate what would be the best size of the image to suit a certain density? I really doubt trying random width and heights is the way to go.
I did some research and found this image:
My basic understanding of maths tells me that I should originally design it for mdpi and then just multiply or divide it to get hdpi/xhdpi/ldpi, is that the right way to go?
What you found here http://developer.android.com/guide/practices/screens_support.html and the formula is 100% correct, the standard is to use 96*96 for xhdpi 72*72 for hdpi 48*48 for mdpi and 32*32 for ldpi but since you didn't follow standard size you can still follow this formula.
Take standard sizes as example on this formula
48*1 = 48 which is mdpi
48*.75 = 32 which is ldpi
48*1.5 = 72 which is hdpi
48*2 = 96 which is xhdpi
I use this tool for re-sizing images. You just need to provide the xhdpi and the tool will scale down the images to different densities. https://code.google.com/p/9patch-resizer/
Related
I see a lot of post on this topic, however I haven't seen an explanation on what image size to take as a reference, let me explain.
I want to add a background image and make it suitable for each phone screen size so from mdpi to xxhdpi (if I'm not talking nonsense)
What size should my base image be?
I used a 600x1200 image and a 1080x1920 then converts using this site
https://romannurik.github.io/AndroidAssetStudio/
Unfortunately I noticed that on my two phones the image was distorted, I'm starting to think my base image size was wrong
So my question
What image size should I take to then create multiple densities ?
Sorry if it's redundant !!!
I'm starting to learn how to adapt and it's not that easy
If you want to create a background picture, your reference size is mdpi with 320x480px. You can then calculate the size according to the factor
hdpi: 1.5 (480x720)
xhdpi: 2.0 (640x960)
xxhdpi: 3.0 (960x1440)
xxxhdpi: 4.0 (1280x1920)
Note however, that nowadays devices have all kinds of other aspect ratios (mostly longer). So you have to design your background in a way, that the outer area does not contain important content. Then use ScaleType CENTER_CROP and your image should not be distorted (https://developer.android.com/reference/android/widget/ImageView.ScaleType)
I think the site is for (mainly launcher) icons.
If your target device's display has 1080x1920 size with xxhdpi (3x) density, just put an image of the size in the res/drawables/xxhdpi folder. No other densities are needed to be prepared. They will be re-scaled from the xxhdpi image if needed.
If you still want to prepare for those densities, first prepare the highest density. If you want to use xxxhdpi (4x), you should start with xxxhdpi sized image. Then scale it down to xxhdpi (3x), xhdpi (2x), hdpi (1.5x) and mdpi (1x).
xxxhdpi (4x): 100%
xxhdpi (3x): 75%
xhdpi (2x): 50%
hdpi (1.5x): 37.5%
mdpi (1x): 25%
Support different pixel densities: Provide alternative bitmaps
I have an image view which has different size on normal and large sized screens(I achived it via dimens.xml), lets assume 100*100 dp on small and 133*133 dp on large sized screen.
I'm setting image to it programatically, let's say it is def.png
Now for best performance I should create 6 versions of def.png(assuming i cater only to mdpi, hdpi and xhdpi densities)
small-mdpi - 100*100 px
small-hdpi - 150*150 px
small-xhdpi - 200*200 px
large-mdpi - 133*133 px
large-hdpi - 199*199 px
large-xhdpi - 266*266 px
It means 6 def.png images, but I can put 3 of them because only 3 folders are available i.e. drawable-mdpi, drawable-hdpi, drawable-xhdpi.
How should I achieve best performance so that there will be less scaling up and down of Images ??
or
If it is not possible this way, then what are the alternatives ?
How to Support Multiple Screens:-
Explicitly declare in the manifest which screen sizes your
application supports
Provide different layouts for different screen
sizes
Provide different bitmap drawables for different screen
densities
Source :- https://developer.android.com/guide/practices/screens_support.html#support
Well, I'm working on the UI for my Android app. And regarding the variety of screen sizes and resolutions, I'm following the known recipe:
MDPI 160DPI 1X (1px)
HDPI 240 DPI 1.5X
XHDPI 320 DPI 2X
Considering this scale, it means manually resize all my icons and buttons on Photoshop, and then load them into the respective folders (mdpi,hdpi and xdpi).
Do you do this in the same way? There is some sort of "auto scaling mode" or something on Android?
All the best,
If you don't want to generate all the icons for all dpi fragmentation, there's a trick. Just generate the icons for xxhdpi or xhdpi and add them into the respective folder. Android itself will resize them in order to fit another fragmentatios but remember that the scale is always done from bigger sizes to smaller, not in the other way.
Hope that helps
I'm currently designing images in four different dimensions (ldpi,mdpi,hdpi and xhdpi) for an Android application. i know that the different drawable folders are used dependig on the dpi of the devices' screen.
But what is the optimal dpi in photoshop to save the pngs?
Should images for ldpi saved with 120dpi, mdpi with 160dpi and so on?
Refer this,
http://developer.android.com/guide/practices/screens_support.html
According to that,
What I would do is design on a 300dpi cavas. That way there's no loss of quality.
// check this Link
You might be confused about what PPI (pixels per inch) to set your deliverables at. Just leave them at the standard 72 PPI, and scale the images accordingly.
Picture's resolution is not important for screen, it's important only for printing.
wide range of products with Android OS. we have from 240x320 px to 640x480 px... Any suggestion to keep design in layout?
What should i do?
Could we work with percentual values?
Yes you can work with percentual values using the layout_weight attribute. See this post for more explanations : What is android:layout_weight attribute?
What you should also consider is adding resources for different screen resolutions and densities. You should read this guide : Supporting Multiple Screens.
Good luck.
Using sp (Scale-independent Pixels) or dp (Density-independent Pixels) while coding is one way for automatic handling of scaling.
I think you should stick to android's hdpi, mdpi and ldpi conventions.
As far as images go. Use this as a rule of thumb.
For each layout, determine the images that are appropriate for an mdpi screen. Then use the conversions below as a guideline for supplying images for the other screen densities.
For ldpi: 1dip = 0.75px
For mdpi: 1dip = 1px
For hdpi: 1dip = 1.5px
For xhdpi: 1dip = 2px
Note that this is a rough guide to help you determine how to scale your images for different screen densities. You may want to vary them depending on how it looks on the screen.
To try out different screen densities, set the abstracted LCD density in your emulator's settings in the following manner:
ldpi 120
mdpi 160
hdpi 240
xhdpi 320
Hope this helps!