Expand clickable area of an ImageView by using padding?

后端 未结 4 847
小蘑菇
小蘑菇 2021-02-04 02:19

I have an ImageView, and I want it to be clickable. The image itself is only 32x32 pixels, but I want the clickable region to be larger so it\'s easier to hit. I was hoping I co

4条回答
  •  花落未央
    2021-02-04 02:39

    Instead of resizing the image (Peter Knego's answer) or increasing padding (Saimon's answer) I suggest to set the minWidth and minHeight attributes in combination with scaleType="center":

    
    

    That makes sure that small images have at least a size of 40x40dp while the image is not up-scaled if it's smaller. If one day the image is going to be replaced with another image larger than minWidth and minHeight it will not grow larger than 40x40dp as it gets downscaled. Thus a minimum clickable dimension of 40x40dp is always guaranted and the image is always displayed nicely.

提交回复
热议问题