Increasing too small ImageView to 48dp touch target size?

Viewed 4963

I have a ImageView with a 24x24 dp icon, so the complete ImageView and touch area is only 24x24dp, while the recommended minimum touch target area is 48x48dp.

What's the common way to increase the ImageView touch area size? I can add a padding of 12 dp on each side manually (24 + 12 + 12 = 48 dp), but is there any better way? Especially if the ImageView size changes I have to adjust padding manually, that's very error prone.

2 Answers

You can set the size of the ImageView to the size of the touchable area.

Then you set the scale type attribute of the ImageView to achieve the desired effect. In your case (icon is likely to be smaller than 48dp x 48dp) this could be android:scaleType="center" or android:scaleType="centerInside".

See the documentation for a description of all options

Using a LinearLayout and an ImageView together may also be a solution.

Keep the imageView inside the LinearLayout and then set the size of linearLayout as 48dp x 48dp and keep the imageView size as 24dp x `24dp and in case if you have any onclick event then you can just replace the ImageView's onclick event with the linearLayout.

Related