Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

My understanding is that when you have a view that's too small to easily touch, you're supposed to use a TouchDelegate to increase the clickable region for that view.

However, searching for usage examples on Google turn up multiple people asking the question, but few answers.

Does anyone know the proper way to set up a touch delegate for a view to, say, increase its clickable region by 4 pixels in every direction?

like image 781
emmby Avatar asked Aug 27 '09 19:08

emmby


1 Answers

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));     } }); 
like image 181
emmby Avatar answered Sep 21 '22 15:09

emmby