我有一个包含
我的代码(虽然很简单):
设置 Oun Touch:
RecyclerView
的ViewPager
,我在RecyclerView
的项内添加了一个图像视图的OnTouchListener
,尝试使用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;
}
设置 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;
}