0

The designer has given me two PNG images and they are supposed to be the background for all the buttons of my app. I am not being able to transform then into 9-patch image. It seems like that one image has too much details to be a 9-patch, stretching it would make it lose the details.

Can you guys take a look and let me know what you think?

http://img211.imageshack.us/img211/1965/background1p.png

http://img845.imageshack.us/img845/676/background2a.png

Many thanks, Felipe

2
  • try using color for 1st. 2nd not possible with 9patch image contains noise dots. Sep 14, 2012 at 12:38
  • Hi Padma. Yeah, for the 1st one I am using a gradient. It works, but I lose the shadow in the bottom part of the image. So I am guessing both images cannot be converted to 9-patch, huh? Sep 14, 2012 at 12:41

4 Answers 4

3

//repeatimage.xml

<?xml version="1.0" encoding="utf-8"?>
    <bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/tileimage"
    android:tileMode="repeat"
    android:dither="true" >

</bitmap>

and set this image in your layout background as

android:background="@drawable/repeatimage"

//slice your image into small pieces

enter image description here

4
  • So this repeating pattern is for the image that contains the noise? Sep 14, 2012 at 12:55
  • I tried, but it didn't work really well I tried creating an image with only the pixels that I want to repeat, but it didnt workout good I tried grabbing a bigger area, but it's also not good. Seems like I will have to skip the pattern then to make this work Sep 14, 2012 at 13:28
  • Padma, does the @tileimage needs to be 9-patch? Sep 14, 2012 at 13:29
  • no not for the tileimage. you need to crop perfectly. can you show how its displaying for you. check androidforbeginners.blogspot.in/2010/06/… Sep 14, 2012 at 14:03
1

Try using this tool . It's a simple 9-patch generator that can be of use to you.

1

For both your questions:

1: I use images with shadows a lot and you can certainly convert them into a 9-patch image. I am not sure how I can explain the actual steps involved in creating this. Perhaps an example will help you work that bit out.

enter image description here

2: For an image with a pattern in it, a 9-patch of it as @Padma Kumar pointed out, will still distort your image. To fix that, you can follow the link attached. It is a nice tutorial on how to use tiled patterns as backgrounds. http://androidforbeginners.blogspot.in/2010/06/how-to-tile-background-image-in-android.html

A side note: The draw9patch can be quite an intimidating tool. Until you get the hang of it, you could consider using this website here: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html. It however, works only in Google Chrome.

0
1

Maybe you should check this tutorial: http://www.thesecretpie.com/2010/07/creating-custom-fancy-buttons-in.html It explains how 9-patch actually works and how to use drow9patch tool which comes with Android SDK. It was really useful for me. And for the shadows, you just need to save image with transparent background (of course) and with a little free space between shadow and edge of an image which you will use to draw lines for 9-patch

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.