滑动和滚动一起工作

时间:2014-03-25 14:08:52

标签: android

我有一个视图,我附加了一个GestureDetector.SimpleOnGestureListener监听器,以实现向左/向右滑动。在这个视图中,我还有一个textview,我为其设置了ScrollingMovementMethod(),并在xml中为它指定了垂直滚动条。在实现滚动之前,滑动工作正常,但滚动滑动检测不再起作用。

为什么ScrollingMovementMethod()阻止了滑动的检测以及如何管理以便同时滑动和滚动?

滑动实施:

gestureDetector = new GestureDetector(this, new SwipeGestureDetector());

gestureListener = new View.OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
    return gestureDetector.onTouchEvent(event);
  }
};

container.setOnTouchListener(gestureListener);

class SwipeGestureDetector extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    flipCard();
                }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    flipCard();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    }

滚动:

<TextView
        android:id="@+id/answerText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="20sp"
        android:textColor="@color/black"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:scrollbars="vertical"/>

answerText = (TextView) findViewById(R.id.answerText);
answerText.setMovementMethod(new ScrollingMovementMethod());

0 个答案:

没有答案