【发布时间】:2018-01-03 18:21:06
【问题描述】:
我的任务是在移动应用程序上实现一项功能。以前我没有使用过 Android 或 Java。
我需要的是一个屏幕(一个片段)来显示两个成员数量奇数的事件列表,我们称它们为ListX和ListY。
我制作了包含两个 RecyclerView 和两个标签的布局(一个标签用作每个回收器视图的标题)。 它像现在一样工作,并且我显示了事件,但 ListX 是可滚动的,即使它的 layout_height 设置为 wrap_content(当时仅显示 6 个项目),而 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 不服从。
Here is sketch of how it should look like
有没有办法将两个列表放在一个 RecyclerView 中并制作自定义分隔符?或者任何其他方式将一个列表的开头锚定到另一个列表的末尾并让它们显示所有项目而不滚动?
我希望在这里得到帮助。
【问题讨论】:
-
如何保证每个recyclerview中的所有项目都是可见的?也就是说,如果您希望两个列表都不滚动,那么当列表大于可用屏幕尺寸时用户会怎么做?
-
我知道这里有一个误解。我的问题是 RecyclerView 有它的嵌套滚动,当我从一个列表向下滚动到另一个 Recycler 时,它是独立滚动的。
-
我需要整个 ScrollView 作为一个组滚动,而不需要 RecyclerViews 的嵌套滚动
-
列表上的项目是动态的,这意味着有时 ListX 上可能有 5 个项目,ListY 上可能有 50 个项目,或者 ListX 上可能有 10 个项目,ListY 上可能有 0 个项目