How do I create good looking drawables. - android

For my app I need several small icons. I put them at a size of 15dp * 15dp in the layout xml file. The problem is that they do not look good on the device. If I look at the standard android Icons, e.g. for refresh, they look very sharp.
What I did was, I created a 15*15 pixel image with Gimp and tried to use it. I guess that is not a good approach since 15dp != 15 px, right? What is the usual workflow for creating nice, good looking icons, even if they need to be small?

Density-independent pixels (i.e. dip or dp in XML) are designed to provide a more consistent visual appearance across devices by scaling the UI to look roughly the same size on each device. This is not the exact same as physical size scaling, but rather the pixel density (dpi) of the screen. There are basically four buckets any device can fall into (ldpi, mdpi, hdpi, xhdpi). The dp unit is modeled after mdpi, and all other buckets are scale factors from there. In other words, 15dp does equal 15px on an mdpi device, but not on others.
What you need to do for optimum performance is to create your icon in four sizes, and place them in corresponding drawable/ directories. For instance, with your 15dp icon you should have:
A 12x12px image in a res/drawable-ldpi folder (LDPI is 75% of MDPI)
A 15x15px image in a res/drawable-mdpi folder (MDPI is the base)
A 23x23px image in a res/drawable-hdpi folder (HDPI is 150% of MDPI)
A 30x30px image in a res/drawable-xhdpi folder (XHDPI is 200% of MDPI)
The application will grab the proper asset to match the resolution of the device you are running on. If you do not create an asset for each level, the application will take the closest match and scale it up or down (You are probably using an HDPI device to test and your 15px image was getting scaled up to 23px, causing pixelation).
HTH!

According to this page, dp is a unit of scale-independent pixels: 160dp always makes 1 inch on your screen. This should answer your question whether pixel is dp or not: It is only the case with a screen supporting 160dpi. This is a lot more than e.g. the usual PC screens these days (96 dpi).

Related

minimum pixels of the largest image's side to fit android xxhdpi screen

I'm making an android App that shows images at full screen.
I learned some about dpi and dp, but I didn't find how many pixel must be the largest side of my images (in prospective to good fit also in landscape mode) to appear good in different devices.
As in the documentation, the most used screen configurations are normal with hdpi, xhdpi and xxhdpi density:
So, if my thinking is correct, I can make only one image to fit the xxhdpi to works fine also with the other two densities, and put it in Android Studio under the "res/drawable" folder (without qualifier).
Specifying the image size in dp in the layout, Android should scale the image for the smaller configurations.
But, for the xxhdpi, how many pixel must be the largest side of my image, in pixel, to show good?
Edit: how many pixel must be the longest side of my image to be showed properly in a device with xxhdpi density without the image appearing grainy?
All images are photo, not icons, so I can't use the vector graphics.
By looking at the Android Documentation. One can estimate the size of the picture. look at below picture
So, your image resolution should be in similar resolution
LDPI: 200 X 320px
MDPI: 320 X 480px
HDPI: 480 X 800px
XHDPI: 720 X 1280px
XXHDPI: 960 X 1600px
XXXHDPI: 1440 x 2560px
A little bit of +/- won't affect the outcome because with these standard sizes the aspect ratio of any portrait picture should be respected.
Well, if you put the image which fits the xxxhdpi inside the folder drawable, then it will fit all the screens.
But there is another way to use only one image instead of using multiple images for different resolutions. It's by using svg images which are vector images that will not be affected by zoom in or zoom out.
To use svg you need to follow these instructions:
Make the icon to be icon.svg
In the Android Studio, right click on drawable folder
Choose New -> Vector Asset
Choose Local File (SVG, PSD)
Choose your svg file
Click Next and choose the name
Click Finish
In the app build.gradle add the following inside android block:
vectorDrawables {
useSupportLibrary true
}
In the xml layout file, add the following:
<AppCompatImageView
android:width="wrap_content"
android:height="wrap_content"
app:srcCompat="#drawable/your_svg_file"
/>
Android have ratios defined for a image to set in all different drawables
Android icons require five separate sizes for different screen pixel densities. Icons for lower resolution are created automatically from the baseline.
mdpi: 160 dpi 1×
hdpi: 240 dpi 1.5×
xhdpi: 320 dpi 2×
xxhdpi: 480 dpi 3×
xxxhdpi:640 dpi 4×
Above size is for normal pixel icons. There are fix android size for Action bar, Dialog & Tab icons, Launcher icons & Notification icons
Check this link for more details http://iconhandbook.co.uk/reference/chart/android/
You have to take a look at the current market of smartphones.
Here you can see the screen sizes and resolutions of the most popular devices in the market.
http://screensiz.es/
Order the list in pixel per inch and you will see that top smartphones have resolutions bigger than 500 ppi or another way to see it, much bigger than 72ppi of your images.
If you have enough space to store or mechanism to download images try to test with full quality. If thats too much try to find a compromise. Lower image quality and see the result in high resolution screen.
Note that you didn't posted here the total size of image, in case is bigger than screen size, take a look at total size of image and compress it to fit your needs, maintaining as much as possible the resolution.
Edit: Looking only to size of image in pixels, the current biggest screen in smartphone is 2560 x 1440 pixels, so you wont need any image bigger than this.
If I understand your answer correctly, you are talking about images (pictures of lovely cats and dogs?) and not about icons?
I prefer putting images into the nodpi folder.
nodpi Resources for all densities. These are density-independent
resources. The system does not scale resources tagged with this
qualifier, regardless of the current screen's density.
Afterwards I would create a fullscreen ImageView and let imageView do the scaling if needed

Android UI manually resize - Autoscale?

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

Adjust view sizes in android for custom devices

I have 3 custom made android devices.
First one has a 5 inch screen with 1280x800 res
Second has a 5 inch screen with 800x480 res
Third has 7 inch screen with 800x480 res
I tried giving sizes with dp, px and inches but it seems they cant support those screens properly with the same value (even inches seems to be not exact inches but translation to px eventually).
How can i use same code to properly adjust view sizes relatively to the screen size?
Well, as first, the correct measure unit to use is: dp for controls and sp for fonts.
These are normally for margin, paddings, widths, heights, and other attributes.
Also xml drawables can take advantage of pixel independency
Define your dimensions in a res/value/dimens.xml file (this is a PROPOSED standard name, you can call it whatever you like best), in order to have them referrable from all your code, instead of being hardcoded and often repeated in many files.
Then you must know that you should provide your graphics AT LEAST in mdpi resolution (160 dpi), which will be scaled up or down to match other resolutions.
Notice that I said at least.
For every resolution you are supporting, you should add a folder in your res path containing the graphics at the corresponding density for that resolution.
this means that you will have, let's say 3 resolutions mdpi, hdpi and xhdpi (today's favourites, excluding tablets - these ones deserve some folders on their own):
The graphics is going into:
res/drawable-mdpi
res/drawable-hdpi
res/drawable-xhdpi
Just put your graphics (with the same names) with (respectively) a dpi density of 160, 240, 320 in those directories.
Now your graphics is resolution compliant.
Now, I don't realize what the problem really is.
I mean, is it the background not fitting well? then the solution is to use a tiling or an "abstract enough" stretchable picture.Or you could use 9 patches, as well
If the problem is how the fonts and other objects interact with each other, you should always reference to an mdpi device (even emulated, if you don't own a physical one). When things scale well on a mdpi device, they are supposed to scale well on every device.
For tablets in particular, you are supposed to provide specific folders for values (where you put your dimens.xml file, containing the dimensions).
These folders normally have names like values-sw600dp or values-sw720dp-land. The suffix land indicates landscape mode, the particle sw###dp indicates the minimum dimension (width or height), so, I guess that in you case you could prepare some folders called values-sw480dp and values-sw480dp-land and there you would put your dimens.xml file, with the special dimensions for that particular device.
I guess that providing only the non-land folder would be enough.

Android: Maintaining image resource size

I know there are tons of questions on this topic, but I tried searching through tons of "android dpi" posts and read the online documentation but haven't found the exact question that I have.
If I want to create a button (or any image resource) that will take up the same space on the screen on all devices - how do I do that?
I understand that there are specific screen sizes and dpi's that Android looks at etc. but I don't quite understand how big a specific image should be to look right on any screen.
Say that I have the following setup for my drawable and layout folders (Application is only landscape):
res/drawable-ldpi/button.png (120 dpi)
res/drawable-mdpi/button.png (160 dpi)
res/drawable-hdpi/button.png (240 dpi)
res/layout-small/main.xml - button is set to 100dp
res/layout-normal/main.xml - button is set to 100dp
res/layout-large/main.xml - button is set to 100dp
Say I have a button that I want to be 100dp on any screen. Following the 3:4:6 scale ratio rule it seems that if I have a button resource that's 100px wide for the mdpi density I should make another button for the ldpi density that's 75px, and one for the hdpi density that's 150px. Is that correct? Do I create the 75px button at 120dpi, the 100px button at 160dpi and the 150px button at 240dpi and then just say android:layout_width="100dp" in all three layout files? Or do I make all three buttons 100px at the different dpi's?
Now what if I have that button 9 patched. Do I have to create the button three times at 120dpi, 160dpi and 240dpi all of which are 100px in size? Or do I just create one 9 patched button at 100px and 160dpi and place it in the mdpi drawable folder?
The online documentation is a bit confusing for me so I'm looking for a simplified answer.
This is for Android versions 1.6+ (Not the new stuff for 3.2 etc)
Thanks for your help ... I just want a button to take up the same space on a 3.7" screen as a 7" screen and not be blurry!
Did you sort this? Afaik, and from my experience, don't change the dpi when creating the images in say, Photoshop. I always left mine at standard which is 72 I think. Regardless, I don't think it matters if you set it to a million.
The px values you mentioned are correct for l m and h.
I would leave the mdpi qualifier off the folder name though; I'm unsure of the protocol if on an xhdpi device there is no drawable folder with no xhdpi qualifier and no folder without qualifiers.
Workflow:
Create your images at 75, 100 and 150.
Put 75 in ldpi folder, 100 in drawables folder with no qualifier, and 150 in hdpi.
Leave your layouts as they are now, with the 100dp. They should scale correctly. That said, I don't think you need to specify the image size if you're using the full resolution.
Comments to address inaccuracies in my answer are always welcome, even years down the line.

Photoshop design from px to dp

I've got a final app design made i Photoshop where everything is measured in PX.
Now I realize that Android apps are using DP for font-sizes and other things.
Is there any way I can convert PX to DP ?
On a more practical note, you have a few choices in increasing work and fidelty:
Have your resources scaled for 160 dots per inch, put them in your res/drawable directory, and let the OS scale them to look right on the device.
Make two copies of your resources: one at 160 dots per inch in your res/drawable and one at 240 dots per inch in your res/drawable-hdpi directory. Let the OS scale for the exact device starting from a pretty close number.
Decide that you don't want any scaling and have raw pixels, so put your assets in the res/drawable-nodpi directory. This means that at 320x480 (pixel) graphic might be 2 inches by 3 inches on one phone but only 1 1/3 inches by 2 inches on another screen.
Specify the exact scaling strategy for your work, using the draw9patch tool. This can be very useful for keeping the corners of boxes from getting the "jaggies" from scaling and for making full screen graphics cope with different aspect ratios.
Make separate graphics for every device you care about and fall back on scalable graphics for the rest. You will need to outrun zealots waving style guides trying to convince you not to do it this way.
Oh, and as a gotcha, specify sp for your fonts, instead of dp or pt. A 10 point font would be a 22 sp font [ =10 * (160/72) or = number of points times 2.222]. sp units scale with user preferences for small, medium, or large fonts.
From this list of the dimension units supported by Android, here's a description of 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".
This means that the "conversion" between pixels and DP will not be consistent -- on some devices, the ratio might be 1DP = 160px, but it could theoretically be anything. This is all well and good when you're setting the width of a button to, say, 100dp (since it will get rendered dynamically), but it presents a problem when you have images which must have a fixed size.
Read this page on "Supporting Multiple Screens" -- Android has something called resource directory qualifiers, which let you create size- and density-specific versions of your image resources. For example, for low-density screens, you could create a smaller version of your image and place it in the drawable-ldpi directory (or drawable-hdpi for high-density screens).
tl;dr You can't practically "convert from PX to DP" (since the ratio is not fixed), but you can create multiple versions of your images and tell Android which to use with resource directory qualifiers.
A pixel is PX and the DP or DIP are device independent pixels. I don't think that you need to convert these. But you can use scalable 9patch images using the draw9patch tool from the android tools.
I have same issue but now got the Solution.
Why you not use the online convertor to see which dp or px you have to for different resolution of android device ??
See this link: this link which helps me a lot and also helps you.
Enjoy coding.
This is a online DP/PX Converter tools: http://labs.rampinteractive.co.uk/android_dp_px_calculator/

Categories

Resources