To my understanding, I need to create several different versions of my image drawables, varying by size so that devices load the appropriate one.
In my Photoshop mockup of my app, I have an icon image that is 12px x 12px on my monitor.
What various sizes/dimensions do I have to make of the icon?
Should the icon stretch to the sides of the drawable's dimensions or should there be some padding?
Thanks.
Scroll down to 'Alternative drawables' to get your answers:
http://developer.android.com/guide/practices/screens_support.html
The size of your photoshop mock up will define what your base is.When I'm not sure what I do is take an icon and drop it in one of the drawable folders, for example let's say xhdpi, and only in that one. From there I launch the app and see how the icon look on my phone. If it's too small then I move to the next folder down, in this case hpdi. If it was too big I would move it to the next folder up, in this case xxhdpi.From there you can calculate the size of the other drawables, using the example on that link.
For reference see the sizes of default ic_launcher icons provided by android for your app in every drawable or mipmap folder when you first create a new project.
See the sizes in pixels and do the same for your custom icon.
Its your wish if you want to give padding to your icon image or not. Its up to you how you want to make your icon look.
Related
I made a single activity app with a picture and a text box and a get started button.Picture isl located at the center,text box just beneath it and button at bottom right corner..but when I run the app the picture and the text box are overlapping each other...and the button is located at the bottom center ......so how to make sure that this doesn't happen.
create dimens in dimens.xml folder for different screen size .
like dimen.xml(sw560dp). and define size for different widgets in different dimens.
Few things you must keep in mind while making screens compatible to multiple screen sizes.
Use dp instead of px in your dimensions.
Use proper layout management. That is use linear layout wherever possible.
Images should have 5 copies for mpdi, hdpi, xhdpi, xxhdpi, and xxxhdpi.
For further details visit this link
Is there a way to get Eclipse to automatically re-size images and put them in the appropriate drawable folders? When you add an image for the icon when you first create an Android project, it automatically re-sizes the icon and puts them in the appropriate folders. I know you're meant to scale images using a 3:4:6:8 scaling ratio (http://developer.android.com/guide/practices/screens_support.html). I'm wondering if there is a way that Eclipse does this automatically for images?
For re-size icons, right click select New/Other… or press Ctrl+N, select Android Icon Set, the default name for icons is ic_launcher, click Next, in Foreground select Image and Browser that image like to put as icon and is re-sized automatically
Is there a way to get Eclipse to automatically re-size images and put
them in the appropriate drawable folders?
NO, until now, you have to create your own resources defined for every "Screen Density", tools like android_img_resizer will work but can´t support all densities, what if you need resources with mhdpi or tvdpi density.
More info:
Supporting Multiple Screens - Using configuration qualifiers
Designing alternative layouts and drawables
Supporting Different Densities
For re-sizing the images in bulk i will recommend you this tool https://github.com/bearstouch/android_img_resizer . its easy to install and it support the new resolutions (xxxhdpi,xxhdpi) as the base image.Check it out.
I want to set a background image into my app. I tried to set my background image in my xml file with android:background(im using a relative layout) but it seems the image was scaled and doesn't appear to be correct or in its original form.
Let's take an example if I want to display it on a 480x800 screen and only on portrait mode. Should I also produce a background image with a resolution of 480x800?
Thanks
Yes you should. Keep in mind that there are three different directories to put your drawables in (ldpi, mdpi and hdpi drawables directories) put your background images in the appropriate directory according to pixel density and the app will chose the appropriate one to use according to the device it is run on.
I would like to show a splash screen image. I've read Screen compatibility overview about the different directories (ldpi, mdpi, ...) to create under res/ but I've not understood if, other than creating the same image of 240x320, 320x480 and 480x800 I need to do other things to achieve a good result.
Can anyone suggest me which is the best thing to do?
What you describe is what you need to do. You need an image for each screen pixel density group (ldpi, mdpi, hpdi and poss xhdpi)
Other things you can do?
Use a background around the image so the image appears to stretch (e.g. if image is white near the edges, use a white background). It'll look better if there isn't an obvious border around the image and it fades into a background.
The background/borders could be a 9-patch, stretchable image
In theory you could provide a lot more images and select them at runtime based on actual screen size, but it's a very bad idea (you never know what new sizes are coming)
Remember to include portrait and landscape versions - never a good idea to assume one orientation if you can possibly avoid it
Think of an Android screen like a resizable web page - they come in various different sizes and shapes, and your layout needs to stretch and adapt for all.
Like Ollie C said, I also make a 9-patch that I set in background, the only probleme with this methos is that your Splashscreen must have uniform stretchable areas.
I have an image put on an ImageButton, which looks good on a mdpi (medium-dpi) screen. However, when the device has a hdpi (high-dpi) screen, the image is still pixel-by-pixel accurate, which look small on the device screen.
How do I make such that the image (and therefore the ImageButton) scaled based on the density-independent pixels (dp or dip) instead of pixels?
android:scaleType="fitXY"
Other choices include :
fitStart
fitCenter
fitEnd
center
cenerCrop
centerInside
matrix
Mind you i'm lazy and use really large PNG images in a raw folder.
As ponkin mentioned, 9-patches are your best bet. Combined with resource directory qualifiers (drawable-hdpi, drawable-mdpi, etc.) you can make assets that look good at any density and size.
An example of 9-patches and resource directory qualifiers can be found in the Multiple Resolutions Android SDK sample. The semi-transparent, black, rounded-corner background is implemented as a 9-patch with different PNGs for ldpi, mdpi, and hdpi.
IMHO you should look pretty close to NinePatchDrawable
. There is, actually, a tool that will help you to make your icon(pictures/icons/whatever...) resizable depending on size of container. It`s really simple and works just fine for my needs. Also look at this article(part "NinePatchDrawable"), it explains the NinePatchDrawable mechanism.
A NinePatchDrawable graphic is a stretchable bitmap image, which
Android will automatically resize to
accomodate the contents of the View in
which you have placed it as the
background. An example use of a
NinePatch is the backgrounds used by
standard Android buttons — buttons
must stretch to accommodate strings of
various lengths. A NinePatch drawable
is a standard PNG image that includes
an extra 1-pixel-wide border. It must
be saved with the extension .9.png,
and saved into the res/drawable/
directory of your project.
Maybe you should just specify button size in device-independent-pixels?
android:layout_width="300dip"
android:layout_height="50dip"