O'Reilly logo

Android Recipes: A Problem-Solution Approach, Third Edition by Jeff Friesen, Dave Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3-14. Forwarding Touch Events

Problem

You have views or other touch targets in your application that are too small for the average finger to reliably activate.

Solution

(API Level 1)

Use TouchDelegate to designate an arbitrary rectangle to forward touch events to your small views. TouchDelegate is designed to attach to a parent ViewGroup for the purpose of forwarding touch events it detects within a specific space to one of its children. TouchDelegate modifies each event to look to the target view as if it had happened within its own bounds.

How It Works

Listings 3-38 and 3-39 illustrate the use of TouchDelegate within a custom parent ViewGroup.

Listing 3-38. Custom Parent Implementing TouchDelegate

public class TouchDelegateLayout extends ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required