Android Gusture 手势识别小案例
Step1: 生成一个Android Gusture Builder程序用于画Gusture然后存储起来用于其它的项目
首先导入 android SDK \android-sdk-windows\samples\android-8\ 目录下的GestureBuilder项目,用于生成Gusture类库
导入过程中要加入几个文件才能导入到Eclipse中,如下图所示: 这几个文件可以从任意android项目中copy
.classpath .project default.properties 3个文件
导入之后生成项目如下图所示: 将该项目安装到模拟器中,如下图所示:
然后会在sdcard
step2:应用此程序生成我们需要的手势,点击 Add gesture按钮添加手势,随便添加几个手势之后
然后会在sdcard中生成一个gusture文件 如图所示
step2:将此gusture文件导出到桌面,然后再复制到新建的项目中去
step3:新建项目Gusture,并将刚才的gusture文件导入到/res/raw目录下 ,如下图所示
step4: 设计应用的UI界面,main.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.gesture.GestureOverlayView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/gesture"
android:gestureStrokeType="multiple"/><!-- 多笔手势 -->
<!-- android:layout_weight="0" 值越低越先赋值
所以先对Button赋值再对android.gesture.GestureOverlayView赋值 -->
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/recognize"
android:onClick="findGesture" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.gesture.GestureOverlayView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/gesture"
android:gestureStrokeType="multiple"/><!-- 多笔手势 -->
<!-- android:layout_weight="0" 值越低越先赋值
所以先对Button赋值再对android.gesture.GestureOverlayView赋值 -->
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/recognize"
android:onClick="findGesture" />
</LinearLayout>
string.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MainActivity!</string>
<string name="app_name">手势识别</string>
<string name="notfind">手势不匹配</string>
<string name="notfull">手势匹配度太低</string>
<string name="recognize">识别</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MainActivity!</string>
<string name="app_name">手势识别</string>
<string name="notfind">手势不匹配</string>
<string name="notfull">手势匹配度太低</string>
<string name="recognize">识别</string>
</resources>
step5:MainActivity.java
[java]
package cn.roco.gesture;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG="MainActivity";
private GestureLibrary library;
private Gesture mygesture;
private GestureOverlayView gestureOverlayView ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
se
补充:移动开发 , Android ,