gpt4 book ai didi

android - GestureOverlayView 不工作

转载 作者:太空狗 更新时间:2023-10-29 15:18:36 25 4
gpt4 key购买 nike

我现在有点困惑:

我使用 Gesturebuilder 创建了 4 个手势1 手势是向上滑动2 手势是向下滑动3 手势是向左滑动4 手势是向右滑动

但是当我尝试在正在运行的应用程序上做手势时只识别左和右,但它的接缝就像上下一样像左右一样因为该方法给了我 getsures 作为 toat

向左滑动提示框显示:向上,向左

我也在我的 Activity 中使用自定义 View 和 OntouchListener,但我无法让它工作

Activity :

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();
}
}
}

}

最佳答案

删除您的 onTouch() 方法,或者至少链接到父类(super class)而不是简单地返回 false,看看是否有帮助。

关于android - GestureOverlayView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10105444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com