목록 활동에 스 와이프 제스처를 구현하려고합니다. 이것은 작동하지만 문제는 터치 이벤트가 목록의 항목을 활성화한다는 것입니다.스 와이프 제스처 및 안드로이드 문제 ListActivity : 제스처가 기본 목록 항목 활성화 중임
다른 답변을 찾았지만 불행히도 해결책을 찾지 못했습니다. 목록 활동에서
: 여기
// Setup the swipe detector
mSwipeGestureListener = new SwipeGestureListener(this);
mGestureDetector = new GestureDetector(mSwipeGestureListener);
mGestureDetector.setIsLongpressEnabled(false);
@Override
public boolean dispatchTouchEvent(final MotionEvent ev)
{
boolean handled = false;
if (mGestureDetector != null)
{
handled = mGestureDetector.onTouchEvent(ev);
}
handled |= super.dispatchTouchEvent(ev);
return handled;
}
그리고 내 제스처 리스너에 대한 코드입니다 : 여기에 내가 사용하고있는 코드는
public class SwipeGestureListener extends GestureDetector.SimpleOnGestureListener
{
protected final Activity mActivity;
protected final int mTouchSlop;
protected final int mMinimumSwipeVelocity;
public SwipeGestureListener(final Activity activity)
{
mActivity = activity;
final ViewConfiguration viewConfiguration = ViewConfiguration.get(activity);
mTouchSlop = viewConfiguration.getScaledTouchSlop();
mMinimumSwipeVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
}
@Override
public boolean onFling(final MotionEvent e1, final MotionEvent e2, final float velocityX, final float velocityY)
{
// Don't handle swipe if Y offset is greater than touch slop
if (Math.abs(e1.getY() - e2.getY()) > mTouchSlop)
{
return false;
}
else
{
if (e1.getX() - e2.getX() > mTouchSlop
&& -velocityX > mMinimumSwipeVelocity)
{
// User swiped finger left.
onSwipeToLeft();
}
else if (e2.getX() - e1.getX() > mTouchSlop
&& velocityX > mMinimumSwipeVelocity)
{
// User swiped finger left.
onSwipeToRight();
}
// We're interested in these series of events
return true;
}
}
// It is necessary to return true from onDown for the onFling event to register
@Override
public boolean onDown(final MotionEvent e)
{
return true;
}
protected void onSwipeToLeft() {}
protected void onSwipeToRight() {};
}
나는 완전히 난처한 상황에 빠진입니다. 제스처가 목록의 기본 항목을 활성화하지 않고도 Android에서 어떻게 제스처를 처리 할 수 있습니까?
P. 루트 레이아웃에서 view.setOnTouchListener를 사용하면 터치 이벤트가 발생하지 않습니다. 그래서 dispatchTouchEvent를 사용했습니다.
도움을 주시면 감사하겠습니다.
감사합니다.