How to programmatically re-apply a 9-patch image to an ImageView?

后端 未结 5 1860
挽巷
挽巷 2020-12-03 23:24

I have an activity that has an ImageView defined inside a HorizontalScrollView. The image source is a 9-patch file that is constrained to stretch only the right edge to fill

5条回答
  •  萌比男神i
    2020-12-03 23:40

    9-patch images seem to only work when they're set as a View's background image. So:

    • instead of android:src, set android:background in your layout XML, and
    • call setBackgroundResource() when you want to change the image.

    You can also use a plain View instead of an ImageView if you want; it doesn't really matter much.

提交回复
热议问题