How to display a tiled background for all resolutions? - android

I have a texture.png which I would like to tile, to create a textured background for my window.
Will I run into any problems with different screen resolutions?
If so, what is the best way to support a textured background for multiple devices?
Should I have 1 image instead? How large should it be?

You should create 3 different versions of your texture and place them in the ldpi, mdpi and hdpi folders appropriately. You can find more on the different densities here. In order to create a background drawable, create an XML file like it is described here: http://developer.android.com/resources/articles/window-bg-speed.html
The attribute android:tileMode="repeat" will do the magic stuff for you. :-)

Related

Android: Adding only two sets of drawables

Is there any way to use only two sets of drawables, one for xxxhdpi and xxhdpi and the other one for xhdpi/hdpi/mdpi/ldpi without having to create 6 drawable-{dpi} folders and duplicating the files.
You can.
Use SVG Images instead of PNG or normal extension pictures.
Then use the following link to convert the SVG to Vector.
Use vector as your drawable, your drawable (single) will support multiple devices.
Cheers!
Vector drawables are the stuff you mean. The limitation is that it is mostly used for drawing simple shapes.
You can sue it like this. Make a vector drawable for xxhdpi and it'll be used for all resolution sizes with suitable sizes automatically. This technique is currently being used to decrease apk sizes reasonably.

Ideal dimensions of a ninepatch background

I want to create a ninepatch background file (the background is a gradient image). I would like to know what are the ideal dimensions of the background image?
In addition to that, where should I put the image: drawable-ldpi, drawable-mdpi or drawable-hdpi?
Check your SDK folder inside: /platforms/android-X/data/res/drawable-hdpi
You will notice there are a bunch of 9patches there. I understand that you should provide a 9patch for each type of device. So you should have a 9patch for ldpi, one for mdpi and one for hdpi.
The idea is to make it as small as possible and also take into account that the 9patch doesn't go smaller than the original.
On the other hand, I don't think that a 9patch will be useful when dealing with gradient images.
I would try using a GradientDrawable.
I think its 40dip x 40dip or 60px x 60px.

fullscreen images and android resolutions

I have a game which displays a full screen image in the background. At the moment I have one image size (1280x800). This works well on large resolutions but on smaller screens the shrinking somewhat degrades the image. You can see jagged edges and it is noticeably worse than what you could achieve using photoshop software.
I have different image sizes, but I am unsure how to utilize them. I know there are different dpi folders, but you can have resolutions of 480x320 and 1280x768 with the same dpi so I don't think these can be of use here.
I believe you can have different layout files for different screen sizes, but the image is not drawn using xml (and in fact would not be possible for my game).
I can only think that I must create a different file name for each size. Then when choosing which image to use I could take the screen dimensions and select the correct one? I am struggling to see how I can make an image look good on both 240x320 and 1280x800 resolutions.
All of the resource qualifiers in the framework can be applied to drawables, not just the dpi designators. In other words, you could create folders like this to segment your images as well:
drawable-ldpi
drawable-xlarge
drawable-normal
drawable-sw480dp
drawable-sw720dp
Even examples like these work...
drawable-v10
drawable-land
And so on...
You can create as many or as few different qualified directories for your image assets as you think necessary to preserve the quality. The Supporting Multiple Screens article in the SDK docs helps describe most of the qualifiers that best fit scaling image assets.
HTH!

How to use 9 patch images in android for different-2 densities(like mdpi,ldpi,hdpi).?

I am creating an android application in which I want multiple screen support.For these I have used 9 patch images.
But my question is this whether using 9 patch images will be enough for different-2 density's devices or I will need to create different-2 9 patch images for varying densities(like mdpi,ldpi,hdpi).
Thanks in advance
I recently found out myself in the same situation so let me pitch in and expand on what has been said already...
Yes, 9-patch images will scale, that's what they exist for. But if you should use a 9-patch image for all screen densities, that depends on the image really. 9-patch images are more commonly used, for instance, buttons. You can have different sized buttons in your app and a 9-patch image will help deal with them, no matter how you size your button (as long as the 9-patch image is properly created).
But let's say your button design has some really round corners for the hdpi version. You create your 9-patch image without messing the corners but when you look at it in the ldpi version, you'll realize your corners are too big for that low resolution. For this situation, you'll need a different 9-patch image with less round corners, that look better on that resolution.
So, the final answer is, it really depends on your image. If you can create a 9-patch image that looks good in all densities, than fine, use it, as you only need one image to handle all densities. But if it doesn't look good, because of corners, gradients, or whatever, than you'll need one 9-patch image for each screen density.
Hopefully it's clearer now.
From documentation: nine patch
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate 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.
the answer is no. you nine patch will scale between different screen size
Short answer is YES.
Check this:
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate
physical size on each device. For example, if your application provides bitmap drawables only for
the baseline, medium screen density (mdpi), then the system scales them up when on a high-density
screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the
bitmaps. To ensure your bitmaps look their best, you should include alternative versions at
different resolutions for different screen densities.
from Android Developer Official Doc

How to make ImageButton in Android automatically scale based on screen density?

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"

Categories

Resources