我有一个ViewPager
,其中包含RecyclerView
我在OnTouchListener
项内的图片视图中添加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;
}
设置oun touch:
{{1}}
答案 0 :(得分:4)
回答我自己的问题感觉有点尴尬:)
如果您在视图组中有视图并且希望在内部视图上获得onFling
,则应覆盖视图组的onInterceptTouchEvent
并返回false