列表视图不在 Android 中的视图翻转器内滚动

发布于 2024-10-03 14:42:16 字数 2937 浏览 4 评论 0原文

视图翻转器有 4 个列表视图。当我使用视图翻转器上实现的手势侦听器翻转视图翻转器时,它工作正常。但我无法滚动列表视图,因为触摸事件无法从视图翻转器向下滚动到列表视图。请提供解决方案。

private class MyViewFlipper extends ViewFlipper implements OnGestureListener {
    GestureDetector gestureScanner = new GestureDetector(this);
    Context context;

    public MyViewFlipper(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) { 
        return gestureScanner.onTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {  
        return gestureScanner.onTouchEvent(event);
    }

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

    @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) {
                this.setOutAnimation(AnimationUtils.loadAnimation(context,R.anim.push_left_out));
                this.setInAnimation(AnimationUtils.loadAnimation(context,R.anim.push_left_in));
                this.showNext();
                return true;
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                this.setOutAnimation(AnimationUtils.loadAnimation(context,R.anim.push_right_out));
                this.setInAnimation(AnimationUtils.loadAnimation(context,R.anim.push_right_in));
                this.showPrevious();
                return true;
            } else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                return true;
            } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                return true;
            }
       } catch (Exception e) {
            e.printStackTrace();
            //Toast.makeText(context, "Error Occurred", Toast.LENGTH_LONG);
       }
       return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        //I want this event to be handled by list view
        this.getCurrentView().findViewWithTag("hierarchy_list").dispatchTouchEvent(e1);

        Log.i(LOG_TAG, "Scroll");
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        //DO something  
        return false;
    }
}

A view flipper has 4 list views. When i flip the view flipper using gesture listener implemented on view flipper, it works fine. But I am not able to scroll the list view since the touch event is not able to trickle down from view flipper to list view. Please provide solutions.

private class MyViewFlipper extends ViewFlipper implements OnGestureListener {
    GestureDetector gestureScanner = new GestureDetector(this);
    Context context;

    public MyViewFlipper(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) { 
        return gestureScanner.onTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {  
        return gestureScanner.onTouchEvent(event);
    }

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

    @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) {
                this.setOutAnimation(AnimationUtils.loadAnimation(context,R.anim.push_left_out));
                this.setInAnimation(AnimationUtils.loadAnimation(context,R.anim.push_left_in));
                this.showNext();
                return true;
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                this.setOutAnimation(AnimationUtils.loadAnimation(context,R.anim.push_right_out));
                this.setInAnimation(AnimationUtils.loadAnimation(context,R.anim.push_right_in));
                this.showPrevious();
                return true;
            } else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                return true;
            } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE &&
                       Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                return true;
            }
       } catch (Exception e) {
            e.printStackTrace();
            //Toast.makeText(context, "Error Occurred", Toast.LENGTH_LONG);
       }
       return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        //I want this event to be handled by list view
        this.getCurrentView().findViewWithTag("hierarchy_list").dispatchTouchEvent(e1);

        Log.i(LOG_TAG, "Scroll");
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        //DO something  
        return false;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼性发作 2024-10-10 14:42:16
@Override
public boolean onInterceptTouchEvent(MotionEvent event) { 
    gestureScanner.onTouchEvent(event);
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {  
    gestureScanner.onTouchEvent(event);
    return false; 
}

希望这个事件能够被传承下来。

@Override
public boolean onInterceptTouchEvent(MotionEvent event) { 
    gestureScanner.onTouchEvent(event);
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {  
    gestureScanner.onTouchEvent(event);
    return false; 
}

Hopefully then the event will be passed down.

む无字情书 2024-10-10 14:42:16

最终我这样做是为了让这件事顺利进行。

        @Override
    public boolean onInterceptTouchEvent(MotionEvent event) { 
        return gestureScanner.onTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {  
//
        this.dispatchTouchEvent(event);
        return gestureScanner.onTouchEvent(event);
    }

Eventually I did this to let the event trickle down.

        @Override
    public boolean onInterceptTouchEvent(MotionEvent event) { 
        return gestureScanner.onTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {  
//
        this.dispatchTouchEvent(event);
        return gestureScanner.onTouchEvent(event);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文