Detailed explanation of the method of realizing custom gesture by Android programming

This paper describes the method of realizing custom gesture by Android programming. Share with you for your reference, as follows:

Previously, I introduced how to use gestures in Android programs, mainly several gestures provided by the system by default. This time, I will introduce how to customize gestures and how to manage them.

First, let's introduce the management of gestures in the Android system. The Android system allows applications to save users' gestures in the form of files. Before using these gestures in the future, you only need to load the gesture library file. At the same time, the Android system also provides functional interfaces such as gesture recognition, search and deletion, as follows:

1、 Load gesture library file:

staticGestureLibrary fromFile(String path); staticGestureLibrary fromFile(File path); staticGestureLibrary fromPrivateFile(Context context,String name);// Load the gesture library staticgesturelibrary fromrawresource (context, int resourceid) from the name file in the data folder of the specified application;

2、 Manage gesture Library:

Next, let's talk about how to customize gestures. Android provides a component called gestureoverlayview, which is specially used to draw customized gestures, and provides three listening interfaces: ongesturelistener, ongestureperformedlistener and ongesturinglistener, which are respectively used to respond to the start, end, completion and cancellation of gesture events. Generally speaking, The ongestureperformedlistener is the most commonly used and can be used to provide a response when a gesture event is completed. The following illustrates how to customize gestures through a program example.

The layout files used are as follows:

1、 Main xml:

2、 Save xml:

The Java code is as follows:

Run the above program to complete the addition of custom gestures. The operation results are shown in the figure:

When you need to use this gesture, you only need to load the corresponding gesture library and call the recognition function interface given above for recognition. It will not be described in detail here. The above content is learned from the book crazy Android

More readers interested in Android related content can view the special topics of this site: summary of Android scroll bar and scroll operation skills, summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and solutions to common problems, summary of Android multimedia operation skills (audio, video, recording, etc.) Android basic component usage summary, Android view skills summary, Android layout skills summary and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>