我有一个包含aViewPager
的RecyclerView
我将aOnTouchListener
添加到RecyclerView
项目内的图像视图中,试图使用GestureDetector.SimpleOnGestureListener
检测触摸,但无法获取onFling
事件。我怀疑是因为RecyclerView
或ViewPager
捕捉到运动事件。我该怎么修?我的代码(虽然很简单):
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;
}
设置盎司触摸:
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;
}
最佳答案
回答自己的问题有点尴尬:)
如果您在视图组中有一个视图,并且希望在内部视图上得到onFling
,则应覆盖视图组的onInterceptTouchEvent
,并返回false