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

保存:

在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:

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

更多相关文章

  1. Android_开发片段(Part 3)
  2. android中下拉框控件——Spinner
  3. ListView 表格动态设置控件宽度
  4. Android重写ViewGroup实现卡片布局(三)
  5. Android手势研究(textview及listview对比验证)(二)
  6. Android:如何将位置信息模式默认设置为高精确度
  7. Android(安卓)控件之ImageSwitcher图片切换器
  8. android中跳转系统自带界面
  9. Textview与Button设置圆角

随机推荐

  1. android 调用系统自带的设置时间日期对话
  2. 【Android(安卓)开发教程】触发事件
  3. Android(安卓)命令行编译、打包生成apk文
  4. 从头学Android之多媒体--使用MediaRecord
  5. Android(安卓)studio进行单元测试
  6. [无线] AndroidManifest.xml配置文件详解
  7. 在Ubuntu16.04下编译FFmpeg4.2.3
  8. android下对存储的操作
  9. Android(安卓)单选/复选控件
  10. Android对接第三方登录,微信登录