Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable intertial scroll in NestedScrollView (Android Studio)

I have a NestedScrollView (part of the default Scrolling Activity) that contains a CoordinatorLayout and RecyclerView to display cards with some information. The layout is designed to allow the cards to go off-screen if there are too many and have the user scroll down to them, however for some reason the scroll does not have momentum to it as it should. I looked around and a previous question told how to disable the intertial scroll in a ScrollView (Android ScrollView disable Inertial scrolling), so I tried to do the opposite:

NestedScrollView mgScrollView = (NestedScrollView) findViewById(R.id.my_games_scroll_view);
mgScrollView.setSmoothScrollingEnabled(true);

But this didn't accomplish it. I tested mgScrollView.setVerticalScrollBarEnabled(true); to see if I was even applying the code to the right view, and so it happens the scrollbars didn't show up either. So now I'm confused as to whether I'm even applying those methods to the right view, but since I don't have any other ScrollViews I'm not sure where it should be if I am incorrect. I know I can add scrollbars in the xml itself but I haven't found xml code for inertial scrolling. Is there a way to add inertia through Java or xml?

Here is the code for content_my_games.xml, which is where the layouts for the cards go (not to be confused with activity_my_games.xml, which houses code for the CollapsingToolbarLayout and FAB)

Thanks

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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/my_games_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.abhinav.sportswowandroid.MyGamesActivity"
tools:showIn="@layout/activity_my_games">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    tools:context=".MyGamesActivity">

    <android.support.design.widget.CoordinatorLayout
            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:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:context=".MyGamesActivity"
            />

    <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
           app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
            />

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </RelativeLayout>
</android.support.v4.widget.NestedScrollView>
like image 659
CodingSingh Avatar asked Jul 11 '16 02:07

CodingSingh


1 Answers

Old question, but just ran into this myself. This solved it for me:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setNestedScrollingEnabled(false);
like image 58
Ignacioxd Avatar answered Nov 15 '22 06:11

Ignacioxd