Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make recyclerview show all item and can not scroll

I am making an app to show all product in 1 view. I want the recyclerview show all item and can not scroll, just scroll parent view( ScrollView ). But problem is can not make height of recycler wrap all content.

-->>I want like this

This is my code:

    <TextView
        android:text="Best seller:"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView4"
        android:textColor="#3f3f3f"
        android:textSize="18sp" />

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:scrollbars="horizontal"
        android:id="@+id/rv_bestSeller"
        android:layout_height="200dp" />

    <TextView
        android:text="New Product"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView5"
        android:textSize="18sp"
        android:textColor="#3f3f3f" />

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:scrollbars="horizontal"
        android:layout_height="200dp"
        android:id="@+id/rv_newProduct"/>

    <TextView
        android:text="All Product"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView6"
        android:textSize="18sp"
        android:textColor="#3f3f3f" />
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/rv_allProduct" />
</LinearLayout>
</ScrollView>

-->>But the space is so small

like image 567
Kul Ken Avatar asked Dec 11 '16 12:12

Kul Ken


1 Answers

You should use NestedScrollView and setNestedScrollingEnabled(false) combined.

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

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

like image 132
Sara Avatar answered Sep 30 '22 05:09

Sara