Category «Android Advanced Concepts»

Dragging and Scaling in Android

This lesson describes how to use touch gestures to drag and scale on-screen objects, using onTouchEvent() to intercept touch events. Drag an Object If you are targeting Android 3.0 or higher, you can use the built-in drag-and-drop event listeners withView.OnDragListener, as described in Drag and Drop. A common operation for a touch gesture is to …

Handling Multi-Touch Gestures in Android

A multi-touch gesture is when multiple pointers (fingers) touch the screen at the same time. This lesson describes how to detect gestures that involve multiple pointers. Track Multiple Pointers When multiple pointers touch the screen at the same time, the system generates the following touch events: ACTION_DOWN—For the first pointer that touches the screen. This …

Animating a Scroll Gesture in Android

In Android, scrolling is typically achieved by using the ScrollView class. Any standard layout that might extend beyond the bounds of its container should be nested in aScrollView to provide a scrollable view that’s managed by the framework. Implementing a custom scroller should only be necessary for special scenarios. This lesson describes such a scenario: …

Tracking Movement in Android

This lesson describes how to track movement in touch events. A new onTouchEvent() is triggered with an ACTION_MOVE event whenever the current touch contact position, pressure, or size changes. As described in Detecting Common Gestures, all of these events are recorded in the MotionEvent parameter of onTouchEvent(). Because finger-based touch isn’t always the most precise …

Detecting Common Gestures in Anroid

A “touch gesture” occurs when a user places one or more fingers on the touch screen, and your application interprets that pattern of touches as a particular gesture. There are correspondingly two phases to gesture detection: Gathering data about touch events. Interpreting the data to see if it meets the criteria for any of the …

Handling the Results in Android

As shown in the previous lesson, you should begin loading your data with a CursorLoader in your implementation of onCreateLoader(). The loader then provides the query results to your Activity or FragmentActivity in your implementation ofLoaderCallbacks.onLoadFinished(). One of the incoming arguments to this method is aCursor containing the query results. You can use this object …