在一个屏幕上有两个RecyclerViews

TipsyFingers

我已获得在移动应用程序上实现功能的任务。以前,我没有使用Android和Java的经验。

我需要的是一个屏幕(一个片段)来显示两个事件列表,这些事件列表的成员数目不一,我们将它们分别称为ListX和ListY。

我制作了包含两个RecyclerViews和两个标签的布局(一个标签充当每个Recycler视图的标题)。它按现在的方式工作,并且显示了事件,但是即使ListX的layout_height设置为wrap_content(此时仅显示6个项目),ListX还是可以滚动的,而ListY则不能滚动并显示集合中的所有事件。

我需要的是ListX中的所有项目都显示在第一个RecyclerView中(无滚动),然后ListY显示在第二个RecyclerView中,也没有滚动。

布局:

<FrameLayout
    android:id="@+id/resultsView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

                <TextView
                    android:id="@+id/label_daily" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/list_daily"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/label_daily"
                    tools:listitem="@layout/fragment_timetracking_event_item" />

                <TextView
                    android:id="@+id/label_unfinished" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/list_unfinished"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/label_unfinished"
                    tools:listitem="@layout/fragment_timetracking_event_item" />

            </LinearLayout>
        </ScrollView>

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

</FrameLayout>

从XML中可以看到,两个RecyclerView都将layout_height设置为wrap_content,但首先没有遵循。

这是它的外观示意图

有什么方法可以将两个列表都放在一个RecyclerView中并创建自定义分隔符?还是通过其他方式将一个列表的开头锚定到另一个列表的末尾,并使它们显示所有项目而无需滚动?

我希望在这里得到帮助。

阿基尔

您不需要2个recyclerViews,可以使用单个recylcerView实现。您应该getItemViewTypebindViewHolder&中阅读有关&的信息。createViewHolder

您可以指定这三种类型

  • 标头
  • DailyItem
  • FinishItem

像这样创建您的列表

  1. 添加每日标题
  2. 添加每日ITEMS
  3. 添加未完成的HEADER
  4. 添加未完成的ITEMS

现在您可以在单个recyclerview中呈现两个列表

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

一个NSManagedObjectContext上有两个NSArrayControllers?

屏幕上有两个圆圈?

一页上有两个sidenav只能使用一个

我在一个页面上有两个表单,但提交按钮正在处理两个验证?

一个NIC(网卡)上有两个IP

在同一个表上有两个联接的竞争性WHERE

两个SATA端口上有一个磁盘,可提供完整的性能

一个View Controller上有两个CollectionViews

一个文件夹在 Ubuntu 18.04 上有两个不同的位置

D3强制布局中的一个节点上有两个标签

一个Apache安装上有两个站点

一个提交按钮上有两个_POST

一个网络上有两个ISP-需要帮助

SQL连接两个表,其中一个表上有一个where子句

从两个表创建一个视图,一个表上有 case 和 sum

只有一个X屏幕工作;如何获得两个X屏幕?

旋转屏幕后,Android显示两个recyclerViews

有没有办法在一个立方体上有两个图像?

一页上有两个BwuDatagrids

一行上有两个正文

在同一模型上有两个指令的问题

具有一个参数的Java通用接口实际上有两个

nginx上有两个站点,但一个站点收到所有请求

如何制作一个具有屏幕尺寸两个div的可滚动flexbox?

有什么办法可以同时在一个屏幕上播放两个YouTube视频?

一个TextBox上有两种绑定?

如何在颤动中在同一个滚动上有两个 ListView.builder?

笔记本电脑上有两个通风口,而不是一个

一个监听器上有多个按钮 - 两个按钮崩溃,一个按钮有效