Using a TouchDelegate

Showing 1-1 of 1 messages
Using a TouchDelegate Justin (Google Employee) 8/27/09 12:38 PM
I was recently asked about how to use a TouchDelegate. I was a bit
rusty myself on this and I couldn't find any good documentation on it.
Here's the code I wrote after a little trial and error.
touch_delegate_view is a simple RelativeLayout with the id
touch_delegate_root. I defined with a single, child of the layout, the
button delegated_button. In this example I expand the clickable area
of the button to 200 pixels above the top of my button.

public class TouchDelegateSample extends Activity {

  Button mButton;
  protected void onCreate(Bundle savedInstanceState) {
    mButton = (Button)findViewById(;
    View parent = findViewById(;

    // post a runnable to the parent view's message queue so its run
    // the view is drawn Runnable() {
      public void run() {
        Rect delegateArea = new Rect();
        Button delegate = TouchDelegateSample.this.mButton;
        delegate.getHitRect(delegateArea); -= 200;
        TouchDelegate expandedArea = new TouchDelegate(delegateArea,
        // give the delegate to an ancestor of the view we're
delegating the
        // area to
        if (View.class.isInstance(delegate.getParent())) {

Android Team @ Google