简体   繁体   English

RecyclerView 中的 android RecyclerView

[英]android RecyclerView inside a RecyclerView

I have a RecyclerView and inside I have a RecyclerView.我有一个 RecyclerView,里面有一个 RecyclerView。 and child RecyclerView is no scrolling I try put a child RecyclerView inside a scrollView NeastedCrollView but it doesn't work :并且子 RecyclerView 没有滚动我尝试将子 RecyclerView 放在 scrollView NeastedCrollView 中,但它不起作用:

No I have this parent recyclerView:不,我有这个父 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>

First of all, don't use NestedScrollView , RecyclerView handles everything about scrolling!首先,不要使用NestedScrollViewRecyclerView处理关于滚动的一切! 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使用下面的链接准则改进和优化您的RecyclerViews,这里的一些有益的参考: https://www.geeksforgeeks.org/how-to-create-a-nested-recyclerview-in-android/ HTTPS://android.jlelse .eu/easy-adding-nested-recycler-view-in-android-a7e9f7f04047

follow one of them step by step!一步一步地跟随其中之一!

you're first need in one recylerView in main activity您首先需要在主要活动中的一个 recylerView

    <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 : 2-在 MainActivity.java 中:

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

3- recyclerView in Layout Adapter: 3-布局适配器中的recyclerView:

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

4- in Adapter : 4 英寸适配器:

    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你在链接中看到完整的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM