Android 9-patch graphic does not scale in image view

I have

<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/ImageView01" android:src="@drawable/phone80"></ImageView> <ImageView android:id="@+id/ImageView02" android:layout_height="wrap_content" android:src="@drawable/underline" android:layout_width="fill_parent" android:layout_gravity="fill_vertical|fill_horizontal"></ImageView> </LinearLayout> 

The first image is a fixed size image that should not be scaled at all. The correct image should be scaled horizontally to the maximum location. The source points to a valid .9.png file. Unfortunately, it always appears only in its original size. What property do I need to install? Is ImageView the right object?

Thanks A.

+7
source share
4 answers

Use android:background instead. And if it's just an underscore, you can use View , not ImageView . As for filling the rest of the screen, you can use TableLayout instead.

Also, make sure your 9 patch is correct. 1px sides should be black. # 000

+22
source

Just add android:scaleType="fitXY" to your ImageView . For example, for myimage.9.png:

 <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/myimage" android:scaleType="fitXY" /> 
+50
source

Also check that the scale lines on the sides do not extend all the way to the corners of the image. I knew that it really didn't make sense that there were black pixels, but I decided that Android would ignore them, but this actually prevents the scaling from working. It also gives the message "ERROR: 9-patch image xxx.9.png malformed" in the output window, but you may not have noticed it. As soon as I pulled out the pixels in the corners, it started working for me.

+1
source

Try using setImageResource (9patchResourceID) instead of setImageBitmap or setImageBackground and it works :)

0
source

All Articles