我现在有点困惑:
我使用Gesturebuilder创建了4个手势 1手势是向上滑动 2手势是向下滑动 3手势是指向左侧的滑动 4手势是向右滑动
但是当我尝试在正在运行的应用上制作手势时 只识别左右,但它的上下接缝也像左右一样 因为这个方法给了我作为一个toat
的诱惑向左滑动的吐司显示:向上,向左
我也在我的活动和OntouchListener中使用自定义视图,但我无法使其工作
活动:
public class RunActivity extends Activity implements OnTouchListener, OnGesturePerformedListener {
static int width;
static int height;
static boolean reset=false;
draw d;
//jump
private GestureLibrary gestureLib;
private static Context mContext;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
d = new draw(this);
d.setOnTouchListener(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
mContext = this;
//get screen size
WindowManager wm = (WindowManager) this.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
width = display.getWidth(); // deprecated
height = display.getHeight(); // deprecated
//Jump
GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
View inflate = d;
gestureOverlayView.addView(inflate);
gestureOverlayView.addOnGesturePerformedListener(this);
gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gestureLib.load()) {
finish();
}
setContentView(gestureOverlayView);
//setContentView(d);
}
public static Context getContext(){
return mContext;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("touch","touched");
if (draw.end == true)
{
reset=true;
}
return false;
}
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
for (Prediction prediction : predictions) {
if (prediction.score > 1.0) {
Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT)
.show();
}
}
}
}
答案 0 :(得分:0)
删除您的onTouch()
方法,或者至少链接到超类,而不是简单地返回false
,看看是否有帮助。