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

请教一个下方View Pager被拉起时的问题? #10

Open
rea-mchi opened this issue Oct 18, 2019 · 2 comments
Open

请教一个下方View Pager被拉起时的问题? #10

rea-mchi opened this issue Oct 18, 2019 · 2 comments

Comments

@rea-mchi
Copy link

header完全展开时会拦截横向滑动的事件,但是把下方vp稍微拉起一点后尝试向左右滑动就不会拦截了。然后这种情况下(header未完全关闭时)拉起vp的话vp还是会有上下左右的滑动,但是我看您的demo就不会出现这种情况,可以请教一下吗?
我和你的onIntercept写法是一样的,但是因为down->move->..->move后,currX - lastX 就小于currY - lastY,拦截不了了..不知道您的demo里这个dx是传到哪里消费掉了orz

@rea-mchi
Copy link
Author

我用了这么一个解决方法:

    override fun onInterceptTouchEvent(
        parent: CoordinatorLayout,
        child: View,
        ev: MotionEvent
    ): Boolean {
        when (ev.actionMasked) {
            MotionEvent.ACTION_DOWN -> {
                lastX = ev.x
            }
            MotionEvent.ACTION_MOVE -> {
                val currY = ev.y
                val headerOpening = // judge whether header is opening
                if (headerOpening){
                    // make horizontal movement is 0
                    ev.setLocation(lastX, currY)
                }
            }
        }
        return super.onInterceptTouchEvent(parent, child, ev)
    }

可以的话还是想请教下您是怎么处理这个问题的, 我在header的behavior里也没有看到有dx的消费

@HirayClay
Copy link
Contributor

HirayClay commented Dec 30, 2019

这个的处理在 UcNewsContentBehavior.java 的 onInterceptTouchEvent 里面,header 完全展开状态下如果尝试左右滑动,会直接拦截掉,然后 CoodrinatorLayout 就不会分发给 vp 处理了,所以 vp 这种状态下是不能左右滑动的,但是稍微上拉一点就不满足拦截条件了,所以又可以左右滑动了

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