Prevent background image from stretching the view

后端 未结 6 1374
予麋鹿
予麋鹿 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

    Why is it so? Because you set the width to wrap_content.

    How can you prevent it:

    a. Set the maxWidth attribute.

    b. Try placing the ImageView with wrap_content inside a Layout that has a fixed width.

    c. (I often use TableLayout as its shrinkColumns and stretchColumns attribute are handy for things like this. Maybe this can work for you too.)

    Too help more, some XML is needed.

提交回复
热议问题