首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >同步ScrollView和NestedScrollView

同步ScrollView和NestedScrollView
EN

Stack Overflow用户
提问于 2015-12-23 07:20:16
回答 1查看 599关注 0票数 2

我有以下布局:

代码语言:javascript
复制
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedscrollview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/inner_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <NESTED VIEWS>

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

        <LinearLayout
            android:id="@+id/outer_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <OUTER VIEWS>

        </LinearLayout>
    </LinearLayout>
</ScrollView>

我的问题是,我希望ScrollView首先滚动,如果ScrollView移动了一点点,否则NestedScrollView就会消耗触摸。目前,NestedScrollView获取触摸事件,并且只在ScrollView接收触摸之后才使用滚动。我试过使用onInterceptTouchEvent并对其进行了实验,但没有结果。有什么指示吗?

这是正确的方法,还是使用其他视图组合?(可能是协调员的布局?)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-23 09:28:18

因此,我扩展了ScrollView并使其工作如下:

代码语言:javascript
复制
private static final int SCROLL_THRESHOLD = 10;

private boolean mScrolling;

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (getScrollY() > SCROLL_THRESHOLD) {
        mScrolling = true;
        onTouchEvent(ev);
        return false;
    } else if (mScrolling) {
        mScrolling = false;
        return false;
    }
    if (ev.getActionMasked() == MotionEvent.ACTION_UP) {
        mScrolling = false;
    }
    return super.onInterceptTouchEvent(ev);
}

为我工作。如果有人有更好的解决办法,请告诉我。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34430584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档