Improving interactions and animations

We have been using a fixed time-step mechanism to manage the animations, but let's see what advantages it gives us to use a scroller class provided by Android to handle the animations, instead of handling all the animations by ourselves.

First, let's create a GestureDetector instance to handle the touch events:

private GestureDetectorCompat gestureDetector =  
        new GestureDetectorCompat(context, new MenuGestureListener()); 

We are using the GestureDetectorCompat from the support library to guarantee the same behavior on older versions of Android.

As we covered in Chapter 3, Handling Events, by introducing a GestureDetector we can greatly simplify our onTouchEvent(), as all the logic will be handled by the ...

Get Building Android UIs with Custom Views 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.