【问题标题】:How to set up 3-levels nested recycler view in Android如何在 Android 中设置 3 级嵌套回收器视图
【发布时间】:2018-07-18 02:28:34
【问题描述】:

我有 3 级列表,我想在 3 级嵌套回收器视图中表示此列表。 因此,我设置了 3 个适配器并将其调整为像这样的 3 个回收器视图 第一级:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  >
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txt_threshold_name"
    android:background="@android:color/holo_red_light"/>
  <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/rv_threshold_list_level_1"
    android:layout_marginLeft="@dimen/pd_14"
    />
</LinearLayout> 

二级

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  >
  <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/rv_threshold_list_level_2"
    />
</LinearLayout>

第三级:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  >
  <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/rv_threshold_list_level_3"
    android:layout_marginLeft="@dimen/pd_14"
    />
</LinearLayout>

我像往常一样设置每个回收站视图。

LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setHasFixedSize(false);

但 2 级和 3 级回收站视图并未准确显示数据。它只显示了 2 级回收器视图的第一项,但下一项的背景仍然存在:

我想知道我是否错过了一些回收站设置以使其正常工作。 请帮帮我!

【问题讨论】:

  • 如果您尝试使用固定高度,这将有助于调试问题...您可以尝试为每个回收站视图使用高度为 100

标签: android android-layout android-studio android-recyclerview recyclerview-layout


【解决方案1】:
    You can use nested scroll view and add as many recylerview inside linear layout

    <android.support.v4.widget.NestedScrollView

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:fitsSystemWindows="true"
            android:scrollbars="none">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                    <android.support.v7.widget.RecyclerView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                    </android.support.v7.widget.RecyclerView>


                    <android.support.v7.widget.RecyclerView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                    </android.support.v7.widget.RecyclerView>



            </LinearLayout>

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

【讨论】:

    猜你喜欢
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2018-06-14
    相关资源
    最近更新 更多