Android的手势的保存
16lz
2021-01-26
对手势感到好奇从网上学习了一部分。
保存:
在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:
这样手势就可以保存了。当然为了可以保存多个手势,手势的名字可以用时间来命名。
更多相关文章
- Android_开发片段(Part 3)
- android中下拉框控件——Spinner
- ListView 表格动态设置控件宽度
- Android重写ViewGroup实现卡片布局(三)
- Android手势研究(textview及listview对比验证)(二)
- Android:如何将位置信息模式默认设置为高精确度
- Android(安卓)控件之ImageSwitcher图片切换器
- android中跳转系统自带界面
- Textview与Button设置圆角