2

I'm trying to create a simple divider using a 9-patch png but I can't seem to get it to stretch correctly. Below is what I have set up on the left and what I want it to do on the right (i scaled it up by 10x to make it easier to see, the real thing is only 16x6 pixels).

enter image description here

I'm using it as a background on an imageview:

<ImageView 
    android:layout_width="fill_parent"
    android:layout_height="2dip"
    android:src="@drawable/divider"
    android:contentDescription="@string/blank">

Here is a screenshot from the app itself:

enter image description here

Where am I going wrong? 9-patch pngs seem to confuse me each time I try to use them.

4

1 回答 1

2

Change android:src to android:background in your xml. ImageViews are used for the actual image, and their scaling depends on scaleType. They don't scale 9patch images the way you'd think. Using background tells it to use it that way.

Side note: You don't even need to use an ImageView, just a simple View with background set will do it.

于 2013-02-18T16:05:57.500 回答