溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android的手勢的保存

發布時間:2020-03-03 09:31:00 來源:網絡 閱讀:593 作者:YuLi1207 欄目:移動開發

 對手勢感到好奇從網上學習了一部分。

 保存:

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

Android的手勢的保存

這樣手勢就可以保存了。當然為了可以保存多個手勢,手勢的名字可以用時間來命名。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女