Is there an example of how to use a TouchDelegate in Android to increase the size of a view’s click target?

I asked a friend at Google and they were able to help me figure out how to use TouchDelegate. Here’s what we came up with:

final View parent = (View) delegate.getParent();
parent.post( new Runnable() {
    // Post in the parent's message queue to make sure the parent
    // lays out its children before we call getHitRect()
    public void run() {
        final Rect r = new Rect();
        delegate.getHitRect(r);
        r.top -= 4;
        r.bottom += 4;
        parent.setTouchDelegate( new TouchDelegate( r , delegate));
    }
});

Leave a Comment