The cyan area shows button boundaries, whereas the pink area shows the bounds of their touch targets.
Take the Material dialog specification for example. The buttons have a minimum height of 36 dp, but for better usability their touch areas should have a minimum height of 48 dp.
The Metrics & keylines section explains why 48 dp × 48 dp is a common minimum size for touch targets:
This is comfortably in the range of recommended target sizes (7–10 mm) for touchscreen objects and ensures that users will be able to reliably and accurately target them with their fingers.
The tedious way with TouchDelegate
The usual way to implement larger touch targets is to use TouchDelegate. Initially it looks simple enough:
Looking into it a bit closer, a few issues crop up:
The values are in pixels, but usually you’d want to use dps here.
The Rect specifies the touch area of a child in local coordinates relative to its parent.
If you just want a touch area that’s 48 dp tall, you’ll need to convert those dps to pixels, get the original touch area, and calculate how much you want to manipulate it’s top and bottom values.
To get the original touch area, the parent needs to complete a layout for its children. This means that simply dropping the code in Activity#onCreate won’t work.
If you’re interested, Google has released sample code for implementing the above. Basically you post a Runnable to the parent’s message queue that calculates the new touch area after everything has been laid out.
To be frank, I don’t want to do all this. I just want to tell the view that its touch target should be 48 dp tall, preferably without new code in my activity.
The view is a subclass of FrameLayout that has some XML attributes that specify the dimensions for the child’s touch target:
And that’s it. Behind the scenes the view reads those attributes, converts them to pixels and does all of the work with TouchDelegate so you don’t have to.
Get the code
You can get the code on GitHub and the compiled library on JCenter. Throw this in your build.gradle:
If you find bugs, please report an issue on GitHub and send me a pull request if you can fix it yourself!