对手势感到好奇从网上学习了一部分。

保存:

在xml中添加手势绘制即类似画板可以绘制手势的:

<android.gesture.GestureOverlayViewandroid:id="@+id/gesture"android:layout_width="match_parent"android:layout_height="match_parent"/>

设置手势的一些属性:

mGov=(GestureOverlayView)findViewById(R.id.gesture);//设置手势多笔画绘制mGov.setGestureStrokeType(GestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE);//设置手势绘制颜色mGov.setGestureColor(Color.BLUE);//设置还未形成的手势颜色为红色mGov.setUncertainGestureColor(Color.RED);//设置手势粗细mGov.setGestureStrokeWidth(15);mGov.setGestureVisible(true);mGov.setFadeOffset(2000);//绑定监听mGov.addOnGesturePerformedListener(this);

设置手势的监听:

//手势绘制完成后保存ViewdialogView=getLayoutInflater().inflate(R.layout.show_gesture,null);ImageViewshow=(ImageView)dialogView.findViewById(R.id.show);finalEditTexteditext=(EditText)dialogView.findViewById(R.id.name);Bitmapbitmap=gesture.toBitmap(128,128,10,Color.BLACK);show.setImageBitmap(bitmap);newAlertDialog.Builder(MainActivity.this).setView(dialogView).setPositiveButton("确定",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){GestureLibrarygestureLibrary=GestureLibraries.fromFile(Environment.getExternalStorageDirectory()+File.separator+"yl_yl");gestureLibrary.addGesture(editext.getText().toString(),gesture);gestureLibrary.save();if(gestureLibrary.load()){Toast.makeText(MainActivity.this,"保存成功",Toast.LENGTH_SHORT).show();}else{Toast.makeText(MainActivity.this,"保存失败",Toast.LENGTH_SHORT).show();}}}).setNegativeButton("取消",null).show();

最后要解绑手势监听:

protectedvoidonDestroy(){mGov.removeOnGesturePerformedListener(this);super.onDestroy();}

手势预览xml:

这样手势就可以保存了。当然为了可以保存多个手势,手势的名字可以用时间来命名。