在多个 TextView 上滑动

Swiping Over Multiple TextViews

我想在多个文本视图上实现滑动功能,其中每个视图都实现一个 onclick 侦听器。我的问题是,如果我将 onTouch 添加到每个文本视图,并且由于它们又小又多,它们将无法识别两者的差异。我试图将 ontouch 添加到父布局,但似乎因为它有文本视图,所以它没有检测到在它们上方滑动。

有谁知道在文本视图上左右滑动并仍然保留它们的 onClick 的好方法吗?

提前致谢。

为了给你一个想法,我有一个 gridview(可以是任何 Layout),其中有很多单元格,用于检测所有这些单元格上的滑动以及检测我关注的每个单元格上的点击代码,当然你需要根据你的需要定制:

private GestureDetectorCompat gestureDetector;                                                               
protected void onAttachments() {
    gestureDetector = new GestureDetectorCompat(this.context, new SingleTapConfirm());
    //get the width and height of the grid view
    final int cellWidth = calendarGridView.getWidth() / 7;
    final int cellHeight = calendarGridView.getHeight() / 5;


    calendarGridView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent touchEvent) {

            int touchX = (int) touchEvent.getX();
            int touchY = (int) touchEvent.getY();

            if(touchEvent.getAction() == MotionEvent.ACTION_MOVE || gestureDetector.onTouchEvent(touchEvent)){

                if (touchX <= calendarGridView.getWidth() && touchY <= calendarGridView.getHeight()) {

                    int cellX = (touchX / cellWidth);
                    int cellY = (touchY / cellHeight);

                    touchPosition = cellX + (7 * (cellY));

                    positionPrinter.setText("child: " + cellX + "," + cellY);
                    cellIDprinter.setText(Integer.toString(touchPosition));

                    // Do you stuff
                    ... ... ... 
                }

            }

            return false;
        }
    });
}

@Override
public boolean onTouchEvent(MotionEvent event) {

    if (gestureDetector != null)
        gestureDetector.onTouchEvent(event);

    return super.onTouchEvent(event);
}private class SingleTapConfirm extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onSingleTapUp(MotionEvent event) {
        return true;
    }
}