[英]onFling not working
I have a ViewPager
which holds a RecyclerView
I add a OnTouchListener
to an image view inside the RecyclerView
's item, trying to detect touches using GestureDetector.SimpleOnGestureListener
but I can't get the onFling
events. 我有一个
ViewPager
,它保存一个RecyclerView
我在RecyclerView
的项内的图像视图中添加了一个OnTouchListener
,试图使用GestureDetector.SimpleOnGestureListener
来检测触摸,但是我无法获取onFling
事件。 I suspect it's happening because either the RecyclerView
or the ViewPager
catching the motion event. 我怀疑这是由于
RecyclerView
或ViewPager
捕获了运动事件而发生的。 How do I fix it? 我如何解决它?
My code (though it's pretty simple): 我的代码(尽管很简单):
public class MyClickListener extends GestureDetector.SimpleOnGestureListener{
public MyClickListener(){
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
Log.d("aaa", "show press");
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
Log.d("aaa", "tapup");
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
Log.d("aaa", "scroll");
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
Log.d("aaa", "long press");
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
Log.d("aaa", "fling");
return false;
}
setting the oun touch: 设置触摸:
public VoiceItemHolder(View view, GestureDetector.OnGestureListener listener) {
super(view);
icon = (CircleButton) view.findViewById(R.id.icon_iv);
touchListener = new GestureDetectorCompat(view.getContext(), listener);
icon.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (touchListener != null)
touchListener.onTouchEvent(event);
return false;
}
Feeling a bit awkward to answer my own question :) 回答我自己的问题有点尴尬:)
If you have a view in a view group and you want to get onFling
's on the inner view you should override the onInterceptTouchEvent
of the view group and return false
如果您在视图组中有一个视图,并且想要在内部视图上获取
onFling
,则应该重写视图组的onInterceptTouchEvent
并返回false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.