Android 9 patch images used for - android

I am having an question regarding 9-patch images in android.
Do we use these 9-patch images only for background purpose or we have some other use of these 9 patches.
I found we use these images in buttons background.
Can anyone suggest excluding buttons where i can use these images.
Thanks.

You can use 9-patch images anywhere as long as it fits your layout purpose. For me, I use 9-patch if i found that the image can "repeat itself somewhere inside".
I use it as divider between two views, view backgrounds, or simply an image itself since I can specify which part it should extend.

We can use specially for multiple screen which is adjustable in any screen size of device.
Here is site to create the 9-patch images.
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html

I use 9-patches to set the background of ANY view doesn't have a fixed weight/height; usually, because of its content has variable size (i.e. it contains a TextView with variable number of lines)
This applies to any kind of view, custom dialogs, buttons, ...

Related

Background for item RecyclerView

For the RecyclerView elements I use CardView. I would like to make each item of the list
A background image is not a problem to prepare. I do not specify the size of the CardView, I have specified match_parent and wrap_content. I do not know what size to make a background image, so that it looks fine on the phones and on the tablets.
Any suggestions? Or do I need to specify the width and height of the item for phones and tablets and already do the background for them? How do experienced developers? vector drawable is not interested yet
To create resizable images you should check out 9-patch. It's the easiest way to fit the image to different ratios. Here you can find a post that better explains how to use it.
To create the image you can either use an online tool, or use the tool provided in Android Studio.

How to create 9patch from image with icon on one side

I'd like to 9patch this image, but I can't seem to
I've tried understanding the things mentioned here https://software.intel.com/en-us/xdk/articles/android-splash-screens-using-nine-patch-png but I can't seem to apply them to my image
Any ideas? And yes, it doesn't help that the icon is rounded ...
According to the linked page you "draw lines that define the stretchable patches.". In your case, the stretchable part seems to be left of the logo until the left half-circle starts.
I added an image with an oversized stretch-line to mark the horizontally stretchable part.
There is no way, to use your image only with 9 path. Best practices for your task - using several images with 9 path. Maybe creating custom view.
1) As you can see, first image, parent with blue color, should include 9 path (it's easy to make without internal image).
2) For best looking in any device you need to create another thing for second image (with facebook char). 9 path for circle - not best idea. So I advice you use holder, with xml canvas background and char "f" in foreground.
3) Now you need to put this all in one FrameLayout, which you will use anywhere. All structure will be as example below:
<FrameLayout> // You may create custom view instead of FrameLayout
// for more flexible and understanding
<BlueImageBackground.9path
gravity=center>
</BlueImageBackground.9path>
<WhiteImageFacebokChar
gravity= center_vertical | left>
</WhiteImageFacebokChar>
</ FrameLayout>
As a result, in any screen, this image will appear identically...
The source image you provided should be edited first, my version:
in sdk/tools folder there is draw9patch tool, so you can use it to edit it. You would see something like this:
Hi it is preferable to create an empty 9 patch image "without the logo" and then setting it as the background of a relative layout and then add an image view to the relative layout and add to the ImageView:
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
Moreover you have to adjust the margin of the image view to achieve the desired result.
Note that this method will not stretch the icon & it requires some fine tuning to the image size and padding to achieve the desired results :-)

What's the proper way to scale/size background images for Android?

I want to have an image cover the background of my Android game, but I'm new to Android development - are there conventions for what file type such an image should be?
What is a conventional size?
What's the proper way to scale/refit this image to different devices (right now I just added the imageresource to the back layout, but this scales the image and distorts it)?
I'm planning on using photoshop and drawing out the image there, is there a more recommended method?
Thanks
"Are there conventions for what file type such an image should be?" The image can be any common file format. PNG is common, probably because it's loss-less and supports transparency, but I don't know the details.
"What is a conventional size?" You will have to produce an image of various resolutions to support all the screens on which your game may be used. You can create new directories in your project tree that look like res/drawable-{screen-type}, where {screen-type} is a screen size/resolution/minimum dimension. For details on how this works see Supporting Multiple Screens.
"What's the proper way to scale/refit this image to different devices?" See #2. To avoid distorting your image, you will need to produce different sized/resolution images to fit various screen sizes.
With regards to Photoshop -- if you are producing a background with a complex design/graphic, you will probably want to use the graphics editor you know best, such as Photoshop. However, if you are making a background that will just be a simple pattern that repeats, or even just a solid, consider making just a small bit of the image, and then using an Android Shape Drawable or Nine Patch Drawable to tile/repeat/stretch your image. This will reduce the number of different-sized images you need to produce for different screens, and will also reduce the space your app takes up, since you will have fewer resources to package. For info on the Drawable resources that Android supports, see Drawable Resources.
The background drawable is stretched by default. If you want to change that, you can create an XML <bitmap> drawable resource referencing your image and set its gravity attribute to something different than fill.
The result can be better if your image is decomposed in different smaller images aligned properly. For exemple, a main background color, a top part and a bottom part. You can then combine the different layers with a Layer list drawable or using a custom layout.

Android Creating Custom Buttons

I have quite a few buttons in my application, they vary in sizes based on the text inside. I want to customize the buttons but I am not sure if I should use
A) Ninepatch pngs
B) Android xml created
C) Photoshop pngs
I want the buttons to scale nicely and therefore not look distorted based on screen size. What are the positives and negatives of the above methods? Is there an ideal way to go about this?
It depends on what they should look like. Rounded corners? Complicated images? Drop shadows? Plain colors?
If you want simple buttons that are monotone in color, xml drawables are the best solution. You can do rounded corners through xml, so if plain is what you are looking for this is the best option.
If you are working with an image, then a 9 patch is the way to go. Play around with the draw9patch tool that comes with the sdk to get the hang of it. You also don't necessarily only need to leave the corners in tack, sometimes you may want to break up the resizable area depending on the image.
PNGs are the last resort as they are the least flexible of the 3 options.
By the way, you should also consider using a state list for all of your buttons, regardless of how you implement the drawable that the button uses. See the link below:
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Does Android layouts work like HTML/CSS layouts?

I have created a button in Photoshop and I have split them into 3 images. Now I want to put those images into android button. I know how to create layouts in android but the point I am missing is how can I make them fluid?
So there is a button for which I have 3 images.
I now want to ask how can I use these images for a <Button> tag so it expands repeating the middle one. Do I need to create style here and then put background="#drawable/three_button_style" or there is something I really need to know?
Is the same going to be true for ListView? I got a list view and images for top, middle and bottom so can I create a ListView of 3 images repeating the middle one?
For scaling items Android usually uses 9-patch, which behaves something like your example but also vertically. Here's a link to the 9-patch tool that can be used to draw these:
http://developer.android.com/guide/developing/tools/draw9patch.html

Categories

Resources