android 9-patch graphic doesn't scale in image view

点点圈 提交于 2019-12-02 18:36:56

Use android:background instead. And if it is just an underline, you can use a View and not an ImageView. As for filling the remainder of the screen, you may want to use a TableLayout instead.

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

ashakirov

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" />

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!