views:

225

answers:

1

Is there a trick to making 9patch images with single pixel borders?

I'm not talking about the single pixel black borders that you use to define the stretchable and content areas. I'm talking about the image itself. If I create an image that has a 1 pixel border around it, often times android will pick one of the edges and stretch it to 2 (or sometimes more) pixels, even though I specifically left the edges out of the stretchable area in the draw9patch utility.

Here is a screenshot of what I mean; in this screenshot I've got two buttons in a vertical LinearLayout with the same background image. The top button obviously has a thicker border, though it shouldn't.

http://www.vimtips.org/media/button_ss.png

Here is a closeup of the screenshot button (on the left) and the actual 9patch image (on the right).

http://vimtips.org/media/images/buttoncmp.png

Buttons are not the only place I've seen this. If I create a background image with a 1 pixel border and use it as the background for ListView rows, sometimes the border appears to be 2pixels instead of just 1.

It's hard to get a UI to look exactly how you want it with these problems. There's got to be a way to get it to appear how you think it should.

+2  A: 

Try with diffrent markers in your 9-patch. Ex. like they use in this example: http://developer.android.com/intl/de/guide/developing/tools/draw9patch.html

I have experienced this myself, than the problem was related with my largeScreen support in the manifest file. And I had not provided correct images in the drawable-hdpi folder etc. Resulting the device scaling the drawable-mdpi drawables.

How many drawable folders do you have?

Do you have this in your manifest ? :

 <supports-screens
      android:largeScreens="true"
      android:normalScreens="true"
      android:smallScreens="true"
      android:resizable="true"
      android:anyDensity="true" />

Make sure you have correct drawables for correct density

PHP_Jedi
I'm using Android 1.5, so I have none of those folders. Perhaps I should target 2.0, but have minSdk set to 1.5?Even so, a ninepatch image should be scalable to any size, right? It shouldn't matter which directory it's in, but maybe I'm thinking about it in the wrong way.
synic
Well, switching to <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="6" /> instead of <uses-sdk android:minSdkVersion="3" /> seems to have fixed my problem. I didn't even create any extra directories, like drawable-mdpi or anything. I'm going to give it to you 'cause you led me to the solution, and you're the only one that added an answer anyway.
synic