기본적으로 모양을 그리기위한 안드로이드 응용 프로그램을 개발하려고합니다. 사용자가 화면에서 제스처를 만들고 제스처와 더 가깝게 일치하는 모양을 화면에 그려야합니다. 내 응용 프로그램에서는 원, 선, 사각형 등과 같이 화면에서 수행되는 제스처를 감지 할 수 있지만 내 코드에는 문제가 있습니다. 실제로 제스처를 감지하여 해당 모양을 그리지 만 한 번만 발생합니다.안드로이드 제스처 탐지
예를 들면. Line에서 화면을 그릴 경우 내보기에서 선이 그려 지지만 이후에는 원이나 사각형 등을 그릴 경우 제스처가 인식되지만 모양은 그려지지 않습니다.
여기에 코드가있는 LinearLayout에서보기 계속 증가 수를 생성합니다처럼 보이는 그
package com.pck.ShapeMaker;
import java.util.ArrayList;
import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.Toast;
public class GestureDetection extends Activity {
private GestureLibrary gLib;
private LinearLayout l1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gesture);
l1 = (LinearLayout) findViewById(R.id.playArea);
gLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gLib.load())
finish();
GestureOverlayView gesturesView = (GestureOverlayView) findViewById(R.id.gestures);
myGestureHandler handler = new myGestureHandler();
gesturesView.addOnGesturePerformedListener(handler);
}
class myGestureHandler implements OnGesturePerformedListener{
public void onGesturePerformed(GestureOverlayView gestureView, Gesture gesture){
ArrayList<Prediction> predictions = gLib.recognize(gesture);
if (predictions.size() > 0 && predictions.get(0).score > 1.0) {
String action = predictions.get(0).name;
if ("l".equals(action)) {
Line line = new Line(getApplicationContext(),20,230,200,230);
l1.addView(line);
} else if ("r".equals(action)) {
Rectangle rect = new Rectangle(getApplicationContext());
l1.addView(rect);
Toast.makeText(getApplicationContext(), "rect", Toast.LENGTH_SHORT).show();
} else if ("t".equals(action)) {
Triangle tri = new Triangle(getApplicationContext(), 300,300,250, 350, 350, 350);
l1.addView(tri);
Toast.makeText(getApplicationContext(), "trianlge", Toast.LENGTH_SHORT).show();
}else if ("c".equals(action)) {
Circle c1 = new Circle(getApplicationContext(),50,50,30);
l1.addView(c1);
Toast.makeText(getApplicationContext(), "circle", Toast.LENGTH_SHORT).show();
}else if ("d".equals(action)) {
Toast.makeText(getApplicationContext(), "diamond", Toast.LENGTH_SHORT).show();
}
}
}
}
}
문제를 해결 했습니까? 동일한 내용입니다. – LoveMeow