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 ...

Get Android Recipes: A Problem-Solution Approach, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.