gpt4 book ai didi

android - 您如何检查是否有人触摸屏幕并向特定方向拖动?

转载 作者:行者123 更新时间:2023-11-29 02:16:10 24 4
gpt4 key购买 nike

我想检查是否有人将手指放在屏幕中央并向右拖动,如何实现?

解决方案: http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/

最佳答案

您可以实现 onTouchListener 并执行如下操作:

public boolean onTouch(View view, MotionEvent event) {
int currentX = event.getX();

if(event.getAction() == MotionEvent.ACTION_MOVE) {
// oldX would be defined as a private property of the class (most likely an Activity)
if(currentX > oldX) {
// moving right

oldX = currentX;
} else {
// moving left or not moving at all

oldX = currentX;
}
}

return true;
}

您或许可以尝试一下,让它按照您想要的方式工作。

关于android - 您如何检查是否有人触摸屏幕并向特定方向拖动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3686576/

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