Android Programming Cookbook
105 / 143
Android Multitouch Example A multi-touch gesture is when multiple pointers (fingers) touch the screen at the same time. The basic class for support touch and multitouch in Android is the MotionEvent class. Motion events describe actions in a set of axis values. The actions are the states that occur when a finger is going down or up. The axis values describe the position of this event and other movement properties. There are single touch events and multi touch events. It depends on the screen of the device if it can handle and report multiple touch events. Multi-touch screens emit one movement trace for each finger, meaning for each pointer. Every pointer (every finger touch) has a unique id, that is assigned when it first touches the screen. A pointer id remains valid until the pointer eventually goes up. In order for our views to react to touch events in an Activity, an OnTouchListener should be registered for each of the views. So, In this example we are going to extend a FrameLayout and use the multi touch events in order to give this Layout some special behaviour. We are going to make a custom onTouchListener for this FrameLayout and override the dispatchTouchEvent(). For our example will use the following tools in a Windows 64-bit or an OS X platform: • JDK 1.7 • Android Studio 1.3.2 • Android SDK 5.1 Let’s take a closer look:
Create a New Android Studio Project
Open Android Studio and choose Start a new Android Studio Project in the welcome screen.