Hand gesture recognition _android of Android Foundation development

Source: Internet
Author: User

For reasons such as precision, gesture recognition is not much used in Android, but it doesn't prevent us from playing this magical thing.

To use gestures in Android, you have to build a gesture library, build a gesture library very simply, create a new Android sample project, build an Android sample project, and then choose the Android version you created, and then see the interface:

Select Gesturebuilder, and then install it on the real machine after it is successful, then add gestures to it and name the gesture.

After creating the gesture, view the system files in Eclipse's File Explore window, and a gesture file in the SDcard folder to export the file to the desktop first. Then create a new project called gesture, create a new raw folder under the Res folder, and then copy the gesture file, so we have a gesture library for this project, and here's how to use this gesture library.

First look at the layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
 xmlns:tools= "http:// Schemas.android.com/tools "
 android:layout_width=" match_parent "
 android:layout_height=" Match_parent "
 tools:context= "com.example.gesture.MainActivity" >

 <android.gesture.gestureoverlayview
 Android:id= "@+id/mygesture"
 android:layout_width= "match_parent"
 android:layout_height= "Match_parent"
 android:gesturestroketype= "multiple"
  />

</RelativeLayout>

In the layout file, there is a control about Gestureoverlayview, and the Android:gesturestroketype property has two values, one is multiple, and the other is single,multiple that supports multiple strokes. Single indicates support for strokes.

Java code:

public class Mainactivity extends activity {private Gestureoverlayview myges;

 Private Gesturelibrary Library;
 @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
 Setcontentview (R.layout.activity_main);
 Myges = (Gestureoverlayview) This.findviewbyid (r.id.mygesture);
 Library = Gesturelibraries.fromrawresource (this, r.raw.gestures);

 Read the data in the library library.load (); Listener Draw gesture Event Myges.addongestureperformedlistener (new Ongestureperformedlistener () {@Override public void Ongestureper Formed (Gestureoverlayview overlay, gesture gesture) {//prediction Stores the result list<prediction> list = library.
  recognize (gesture);
  Traversal results, score is the score after the pair, the greater the score, the more similar for (prediction p:list) {log.i ("Lenve", p.name+ "------------" +p.score);
  } if (List.get (0). score>4) {toast.maketext (mainactivity.this,list.get (0). Name, Toast.length_long). Show ();
  }else{Toast.maketext (mainactivity.this, "gesture unrecognized", Toast.length_long). Show (); }
  }
 });

 }
}

Critical code has been commented. As simple as this, because of the identification rate and other problems, gesture recognition is currently not used much.

Original link: http://blog.csdn.net/u012702547/article/details/45727729

SOURCE Download: Android Development gesture recognition

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.