对手势感到好奇从网上学习了一部分。
保存:
在xml中添加手势绘制即类似画板可以绘制手势的:
<android.gesture.GestureOverlayView
android: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);
设置手势的监听:
// 手势绘制完成后保存
View dialogView = getLayoutInflater().inflate(R.layout.show_gesture,
null);
ImageView show = (ImageView) dialogView.findViewById(R.id.show);
final EditText editext = (EditText) dialogView.findViewById(R.id.name);
Bitmap bitmap = gesture.toBitmap(128, 128, 10, Color.BLACK);
show.setImageBitmap(bitmap);
new AlertDialog.Builder(MainActivity.this).setView(dialogView)
.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
GestureLibrary gestureLibrary = 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();
最后要解绑手势监听:
protected void onDestroy() {
mGov.removeOnGesturePerformedListener(this);
super.onDestroy();
}
手势预览xml:
这样手势就可以保存了。当然为了可以保存多个手势,手势的名字可以用时间来命名。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。