Android OnGestureListener Fling 未检测到
我想检测屏幕块中的快速移动。我正在使用以下代码。
public class MyinfoActivity extends Activity implements OnGestureListener {
@Override
public void onCreate(Bundle savedInstanceState) {
..........
..........
gestureScanner = new GestureDetector(this);
resBlock = (TableRow) findViewById(R.id.ResBlock);
gestureScanner = new GestureDetector(this);
}
@Override
public boolean onTouchEvent(MotionEvent me){
Log.d(null,"Touch");
if (gestureScanner.onTouchEvent(me))
return gestureScanner.onTouchEvent(me);
else
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
Log.d(null,"Fling");
............
............
}
@Override
public boolean onDown(MotionEvent arg0) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}
它正在检测 TouchEvent,但没有检测到任何猛击动作。我的代码有什么问题?
I want to detect fling motion in a block of the screen. I am using the following code for that.
public class MyinfoActivity extends Activity implements OnGestureListener {
@Override
public void onCreate(Bundle savedInstanceState) {
..........
..........
gestureScanner = new GestureDetector(this);
resBlock = (TableRow) findViewById(R.id.ResBlock);
gestureScanner = new GestureDetector(this);
}
@Override
public boolean onTouchEvent(MotionEvent me){
Log.d(null,"Touch");
if (gestureScanner.onTouchEvent(me))
return gestureScanner.onTouchEvent(me);
else
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
Log.d(null,"Fling");
............
............
}
@Override
public boolean onDown(MotionEvent arg0) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}
It is detecting the TouchEvent, but it is not detecting any fling motion. What is the problem in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用了以下代码并解决了该问题。
I used the following code and solved the issue.
首先,您的 onTouchEvent 方法不正确,将导致gestureScanner 对象对 onTouchEvent 进行 2 次调用。
你需要这样改变:
你也有这行两次:
然后尝试改变你的 onFling 方法,如下所示:
First your onTouchEvent method is incorrect and will cause 2 call of onTouchEvent by the gestureScanner object.
You need to change by this :
You also have this line twice :
Then try to change your onFling method like this :
在
onDown
方法中返回true
return
true
in youronDown
method