Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No release momentum inside ScrollView

In my activity, I have two RecyclerViews inside a ScrollView. The problem is that when I swipe/flick the ScrollView, scrolling stops immediately. Is there a way to get the ScrollView to implement momentum or inertia so there's some deceleration before the scrolling stops?

My XML is below:

<?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>

like image 560
kelvin Avatar asked Jan 15 '16 06:01

kelvin


2 Answers

I figured it out! All I had to do was set setNestedScrollingEnabled(false); to the two RecyclerViews, and everything started working like a charm.

like image 199
kelvin Avatar answered Nov 11 '22 15:11

kelvin


You can disable nested scrolling directly in your XML with: android:nestedScrollingEnabled="false"

So your XML would look like:

<?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>
like image 40
Matt Harvey Avatar answered Nov 11 '22 14:11

Matt Harvey