S
S
Sergey Semenko2016-05-30 11:32:56
Android
Sergey Semenko, 2016-05-30 11:32:56

Android. Incorrect scrolling of RecyclerView inside NestedScrollView. How to fix?

There is a layout like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@color/colorPrimaryDark">

    <android.support.v4.widget.NestedScrollView
        android:scrollbars="none"
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/main_button">

            ...

            <android.support.v7.widget.RecyclerView
                android:id="@+id/bets_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/chance_list"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"/>

        </RelativeLayout>

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

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Внести предметы"
        android:id="@+id/main_button"
        android:background="@drawable/main_button"
        android:textColor="@android:color/white"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"/>

</RelativeLayout>

Code in MainFragment:
RecyclerView betsList = (RecyclerView) view.findViewById(R.id.bets_list);
BetsAdapter betsAdapter = new BetsAdapter(getActivity(), getData());
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
betsList.setLayoutManager(linearLayoutManager);
betsList.setAdapter(betsAdapter);

Everything works, but scrolling the RecyclerView list is not the same as scrolling the NestedScrollView: by swiping up / down, the list does not scroll on its own. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Perelygin, 2016-05-30
@orcDamnar

Hello. Putting a scrollable container in a scrollable container is very bad. Try to reconsider the layout and the need for such an approach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question