您的位置:首页 > 移动开发 > Android开发

android手势识别

2016-07-17 22:19 302 查看

android手势识别

详细步骤不说了





手势识别代码   http://download.csdn.net/detail/zhupengqq/9578532

运行上边这个项目之后,会生成这样一个手势识别库gestures,新建一个项目,
在res下面,建立一个raw文件夹,然后引入这个库

下面是具体实例:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.gesture.GestureOverlayView
android:id="@+id/gestureOverlayView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/aa"/>
</android.gesture.GestureOverlayView>

</LinearLayout>
<spanstyle="font-size:14px;">packagecom.example.gusturedetecterdemo2;

importjava.util.ArrayList;

importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.gesture.Gesture;
importandroid.gesture.GestureLibraries;
importandroid.gesture.GestureLibrary;
importandroid.gesture.GestureOverlayView;
importandroid.gesture.GestureOverlayView.OnGesturePerformedListener;
importandroid.gesture.Prediction;
importandroid.view.GestureDetector;
importandroid.view.GestureDetector.SimpleOnGestureListener;
importandroid.view.Menu;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.View.OnTouchListener;
importandroid.widget.ImageView;
importandroid.widget.SimpleAdapter;
importandroid.widget.Toast;

publicclassMainActivity2extendsActivity{
privateGestureOverlayViewgestureOverlayView;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
gestureOverlayView=(GestureOverlayView)findViewById(R.id.gestureOverlayView1);
finalGestureLibrarylibrary=GestureLibraries.fromRawResource(MainActivity2.this,R.raw.gestures);
library.load();
gestureOverlayView.addOnGesturePerformedListener(newOnGesturePerformedListener(){

@Override
publicvoidonGesturePerformed(GestureOverlayViewoverlay,Gesturegesture){
//TODOAuto-generatedmethodstu读出手势
//读出手势中的内容,识别手势
ArrayList<Prediction>mygesture=library.recognize(gesture);
Predictionpredction= mygesture.get(0);
if(predction.score>5.0){
if(predction.name.equals("宿")){
Toast.makeText(MainActivity2.this,"一元钱代金券",Toast.LENGTH_LONG).show();
finish();
}
if(predction.name.equals("五角")){
Toast.makeText(MainActivity2.this,"五角钱代金券",Toast.LENGTH_LONG).show();
}
if(predction.name.equals("一")){
Toast.makeText(MainActivity2.this,"两角钱代金券",Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(MainActivity2.this,"没有该手势",Toast.LENGTH_LONG).show();
}
}
});
}
}
</span>
运行之后,滑动界面,就会出现手势识别,

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: