android手势识别
2016-07-17 22:19
302 查看
android手势识别
详细步骤不说了手势识别代码
运行上边这个项目之后,会生成这样一个手势识别库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>
相关文章推荐
- android 打造不同的Seekbar
- android 打造不同的Seekbar
- android 打造不同的Seekbar
- Android开发 Java解析Json字符串
- android button的使用
- android反编译apk
- Translucent System Bar
- 【Android】ORM数据库框架之GreenDao【关联】关系操作
- android线程
- 关于Android图片分辨率应该放到哪个文件夹的问题(drawable-hdpi......)
- android项目重构经验总结
- Android数据存储方式简括
- android数据库版本升级,在onUpgrade方法如何写,防止跨级重新创建数据表而报错
- Android开发之实现两个手机之间的通讯
- Android基础
- Android——简单模拟银行转账
- Android设计模式之命令模式
- Android中项目中集成百度地图
- 转行|如何成为企业想要的Android工程师
- android studio 怎么将项目打包成apk文件