Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能不能控制左右滑动的时候就不上下滑动 #305

Open
Alembertcn opened this issue Aug 17, 2023 · 2 comments
Open

能不能控制左右滑动的时候就不上下滑动 #305

Alembertcn opened this issue Aug 17, 2023 · 2 comments

Comments

@Alembertcn
Copy link

能不能控制左右滑动的时候就不上下滑动 上下滑动的时候就不触发左右滑动

@Alembertcn
Copy link
Author

有个取巧的方法 就是设置他的高度足够大 然后外部包裹一层ScrollView 完美解决了互斥滑动 底部还能再加个--暂无更多--的标志

@plumcookingwine
Copy link

plumcookingwine commented Jun 12, 2024

MatrixHelper用于控制手势滑动,GestureDetector其中监听手指滑动监听,可以在OnTableGestureListener的onScroll方法进行拦截处理

@Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

            if (onInterceptListener == null || !onInterceptListener.isIntercept(e1, distanceX, distanceY)) {

/**
     * 滚动时如果已经确认了滚动方向,就不需要再给isScrollX赋值了
     */
                if (!confirmScroll) {
                    isScrollX = (Math.abs(distanceX) - Math.abs(distanceY)) > 0;
                    confirmScroll = true;
                }

                if (isScrollX) {
                    translateX += distanceX;
                } else {
                    translateY += distanceY;
                }
                notifyViewChanged();
            }
            return true;
        }

confirmScroll 和 isScrollX 可以设置为成员变量

在down时,初始化上面的变量

@Override
        public boolean onDown(MotionEvent e) {
            isFling = false;
            confirmScroll = false;
            return true;
        }

这样就可以解决左右上下可以同时滚动的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants