3

Iam trying to place a RecyclerView inside a NestedScrollView. The problem is that if I place the RecyclerView inside a horizontal LinearLayout, the recycler view shows. But if I place it into Vertical LinearLayout it doesnot show up. Here is something that I have tried:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginBottom="32dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="80dp">
                <android.support.v7.widget.Toolbar
                    android:id="@+id/anim_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="20dp"
                    android:background="@color/AppBrightRed"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/ic_appicon"
                    android:layout_marginLeft="10dp"
                    android:layout_gravity="bottom|left" />
            </FrameLayout>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical">
            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:name="com.google.android.gms.maps.MapFragment"
                app:layout_collapseMode="parallax" />
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:scrollbars="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
                <AutoCompleteTextView
                    android:layout_height="wrap_content"
                    android:layout_width="180dp"
                    android:hint="LOCATION"
                    android:id="@+id/ATView" />
                <Button
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="Checkin"
                    android:textColor="@color/AppBackground"
                    android:id="@+id/btnCheckin"
                    android:background="@color/AppBrightRed" />
                <android.support.v7.widget.RecyclerView ----DOES NOT SHOW IF PLACED HERE
            android:id="@+id/recyclerView"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
              </LinearLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

How can I solve this?

hello world
  • 797
  • 1
  • 9
  • 31
  • Change `layout_height` of recyclerview's parent linear layout to `match_parent` – Apurva Nov 04 '15 at 04:35
  • @Apurva thanks for the reply. but that doesn't work either – hello world Nov 04 '15 at 04:38
  • 2
    Possible duplicate of [How to use RecyclerView inside NestedScrollView?](http://stackoverflow.com/questions/31000081/how-to-use-recyclerview-inside-nestedscrollview) – DmitryArc Nov 04 '15 at 09:02
  • Please avoid using recyclerView inside Scroll View. If you gonna make it work by somehow, it still be problem for future and for app scrolling performance. Android strongly discard this type of design. – Mahendra Chhimwal Dec 10 '15 at 07:29

2 Answers2

4

you can use LinearLayout instead of NestedScrollView:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        />

    </LinearLayout>
javad
  • 833
  • 14
  • 37
  • Huh. This works. I used a `FrameLayout` instead of a `LinearLayout` and it *also* worked! Note that I programatically call `setNestedScrollingEnabled(true)` on the `RecyclerView`. Weird, I didn't think collapsing/scrolling would still work, but it did!! Thanks for the tip. – Matthew Housser Mar 12 '16 at 09:20
0

You could take a look at : How to use RecyclerView inside NestedScrollView?

By the way, it won't work i've tried everything you can even imagine it.

But, you have these options:

1. Using a Library like https://github.com/serso/android-linear-layout-manager

2. Or, implementing your own custom LinearLayoutManager

3. or Using app:layout_behavior="@string/appbar_scrolling_view_behavior" on both.(perhaps it will works)

And of coure, you could use that inside CoordinatorLayout and outside the NestedScrollView.

Check this answer: https://stackoverflow.com/a/34951558/4409113

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108