ScrollView 内部没有释放动力

No release momentum inside ScrollView

在我的 activity 中,我在一个 ScrollView 中有两个 RecyclerView。问题是当我 swipe/flick ScrollView 时,滚动立即停止。有没有办法让 ScrollView 实现动量或惯性,以便在滚动停止之前有一些减速?

我的XML如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ProgressBar
    android:id="@+id/threadload_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:visibility="gone" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/subforums"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_subforum"/>

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/threadlist"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_thread"/>

</LinearLayout>
</ScrollView>

我想通了!我所要做的就是将 setNestedScrollingEnabled(false); 设置为两个 RecyclerView,然后一切都开始正常工作了。

您可以直接在 XML 中禁用嵌套滚动:android:nestedScrollingEnabled="false"

所以你的 XML 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ProgressBar
    android:id="@+id/threadload_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:visibility="gone" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/subforums"
        android:nestedScrollingEnabled="false"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_subforum"/>

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/threadlist"
        android:nestedScrollingEnabled="false"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_thread"/>

</LinearLayout>
</ScrollView>