Zhen Liu
Zhen Liu

Reputation: 7920

How to make recyclerView to scroll vertically with parent?

I would like to have a recycler view to scroll together with the whole parent, but currently it is scrolling within its tiny amount of space.

I have a android layout like so

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    <SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout 
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView />
                <RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="150dp" /> <- this scrolls horizontally

                <TextView />
                <RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="150dp" /> <- this scrolls horizontally
                             <- at this point the screen is half filled

                <TextView />
                <RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" /> <- I wish this to scroll vertically
                             <- but I want the whole screen to scroll, not just half the screen.
                             <- And as user scrolls down, this recycler view should be able to grow itself for pagin..

            </LinearLayout>
        </NestedScrollView>
    </SwipeRefreshLayout>
</LinearLayout>

My question is, how do i make the 3rd recycler view to scroll together with everything? Currently for some reason it is scrolling under with its 50% screen height.

Upvotes: 2

Views: 2322

Answers (1)

ZeroOne
ZeroOne

Reputation: 9117

add setNestedScrollingEnabled(false); to your recyclerview

RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);

Upvotes: 4

Related Questions