1

I have a RecyclerView and inside I have a RecyclerView. and child RecyclerView is no scrolling I try put a child RecyclerView inside a scrollView NeastedCrollView but it doesn't work :

No I have this parent recyclerView:

 <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/vehicle_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="@dimen/text_dp_20"
        android:paddingTop="10dp"
        android:scrollbars="none"
        tools:ignore="MissingConstraints" />

and this is a child list :

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:scrollbars="none" />


</androidx.core.widget.NestedScrollView>
kiki Kala2
  • 399
  • 5
  • 19

2 Answers2

0

First of all, don't use NestedScrollView, RecyclerView handles everything about scrolling! use the below links guidelines for improving and optimizing your RecyclerViews, here some useful references: https://www.geeksforgeeks.org/how-to-create-a-nested-recyclerview-in-android/ https://android.jlelse.eu/easily-adding-nested-recycler-view-in-android-a7e9f7f04047

follow one of them step by step!

Yasin Hajilou
  • 247
  • 3
  • 11
0

you're first need in one recylerView in main activity

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/> 

2-and in MainActivity.java :

   LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this);
    ItemAdapter itemAdapter = new ItemAdapter(buildItemList());
    rvItem.setAdapter(itemAdapter);
    rvItem.setLayoutManager(layoutManager);

3- recyclerView in Layout Adapter:

  <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_sub_item"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

4- in Adapter :

    LinearLayoutManager layoutManager = new LinearLayoutManager(
            itemViewHolder.rvSubItem.getContext(),
            LinearLayoutManager.VERTICAL,
            false
    );
    layoutManager.setInitialPrefetchItemCount(item.getSubItemList().size());

    // Create sub item view adapter
    SubItemAdapter subItemAdapter = new SubItemAdapter(item.getSubItemList());

    itemViewHolder.rvSubItem.setLayoutManager(layoutManager);
    itemViewHolder.rvSubItem.setAdapter(subItemAdapter);
    itemViewHolder.rvSubItem.setRecycledViewPool(viewPool);

the end.

you see full code in link

Javad Dehban
  • 1,282
  • 3
  • 11
  • 24