【发布时间】:2016-01-20 17:04:46
【问题描述】:
下图是 Google I/O 2015 应用程序的第一页。
我想实现这样的目标。每张卡片中的每个部分,RecyclerView 中的一些细节以及右上角的More 按钮。
我试过类似的东西,
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/root">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Updates"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:id="@+id/updates">
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Videos"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:id="@+id/videos">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
但是,我不确定这是否是正确的方法。我们是否需要为每个部分使用每个RecyclerView?假设,如果我有 5 个部分,那么我应该有 5 个RecyclerView?
【问题讨论】:
-
你不应该使用多个 RecyclerViews。您可以按部分将所需的设计归档到您的 RecyclerView。有很多方法可以将部分添加到 RecyclerView。如果您是新手,请使用一些库项目,例如 github.com/afollestad/sectioned-recyclerview
-
是的,他说得对,就像我说的,会占用大量内存,而且所有用户根本无法使用它。
-
@Sharj 我看过那个库。我有多个带有自定义对象的数组列表,我保存了从 Web 服务获得的那些更新、视频、文章数据。如何为具有多个
arrayList的适配器设置单个recyclerView? -
@LinX64 你什么也没说。但是,“为什么像我说的那样”?
-
我在回答中说过!
标签: android android-layout android-recyclerview