Android ImageView 手势/双击不触发
好的,所以我有这个设置
ScrollView 水平滚动视图 ImageView
我试图捕获图像视图上的 doubleTap.. 我的代码如下所示:
ImageView iv = (ImageView)findViewById(R.id.ImageViewID);
iv.setImageDrawable(iv.getResources().getDrawable(R.drawable.someimage));
// Gesture detection
detector = new GestureDetector(this,new SimpleOnGestureListener(){
//new myGestureClass());
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
System.out.println("SINGLE TAP");
return false;
}
@Override
public boolean onDoubleTap(MotionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("DOUBLE TAP");
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("DOUBLE TAP EVENT");
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
});
View.OnTouchListener gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
System.out.println("TOUCH!" +event);
if (detector.onTouchEvent(event)) {
return true;
}
return false;
}
};
iv.setOnTouchListener(gestureListener);
然而,重写的点击方法永远不会被调用... onTouch 确实被调用,但 detector.onTouchEvent(event) 应该绑定我的事件到触摸事件,永远不会调用我的 overRidden 方法......那么,我到底做错了什么?
Ok, so I have this setup
ScrollView
HorizontalScrollView
ImageView
I am trying to capture the doubleTap on the Image View.. my code looks like the following:
ImageView iv = (ImageView)findViewById(R.id.ImageViewID);
iv.setImageDrawable(iv.getResources().getDrawable(R.drawable.someimage));
// Gesture detection
detector = new GestureDetector(this,new SimpleOnGestureListener(){
//new myGestureClass());
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
System.out.println("SINGLE TAP");
return false;
}
@Override
public boolean onDoubleTap(MotionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("DOUBLE TAP");
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("DOUBLE TAP EVENT");
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
});
View.OnTouchListener gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
System.out.println("TOUCH!" +event);
if (detector.onTouchEvent(event)) {
return true;
}
return false;
}
};
iv.setOnTouchListener(gestureListener);
Yet the overridden tap methods never get called... The onTouch does get called but the detector.onTouchEvent(event) that should be tying my events to the touch event, never ever calls my overRidden methods.... So, what the heck am I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重写 onDown 方法并返回 true。 来源
希望有所帮助。
Override onDown method and return true. Source
Hope this help.