Prevent background image from stretching the view

后端 未结 6 1371
予麋鹿
予麋鹿 2021-02-18 12:36

Whenever I assign background to a view that is laid out with wrap_content, if the background image is larger than a view, the view is stretched so that it can hold the entire ba

6条回答
  •  野性不改
    2021-02-18 13:18

    This might be a crazy idea, but how about creating a special nine-patch image like this:

    • take the original image
    • add 2 pixel border around it (1 pixel border for the 9-patch marking, and 1 pixel empty border)
    • mark the empty border as stretchable

    This way you will have 2 stretchable areas horizontally, and 2 vertically, which is the empty border. Thus the center of the image (your original image remains unscaled)

    Btw, this might not be the best solution, but since the others already listed the nice solutions, I thought I add this one as well ;-)

提交回复
热议问题