我已获得在移动应用程序上实现功能的任务。以前,我没有使用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实现。您应该getItemViewType
在bindViewHolder
&中阅读有关&的信息。createViewHolder
您可以指定这三种类型
像这样创建您的列表
现在您可以在单个recyclerview中呈现两个列表
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句