O'Reilly logo

Building Android UIs with Custom Views by Raimon Ràfols Montané

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

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

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