【问题标题】:Layout design for Cards like Multiple Section in android?android中多个部分等卡片的布局设计?
【发布时间】: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


【解决方案1】:

是的,您可以为每个部分使用RecyclerView但是,我认为这会占用大量内存。

另外,将它们放入CardView 中,每个部分都像这样:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="360dp"
    android:layout_height="300dp"
    android:layout_marginStart="12dp"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardCornerRadius="4dp"
    card_view:cardElevation="2dp">

    <RelativeLayout
        android:id="@+id/root"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Updates"
            android:id="@+id/textView" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/updates"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:layout_below="@+id/textView" />

    </RelativeLayout>
</android.support.v7.widget.CardView>

【讨论】:

  • 等待更好的解决方案。
  • 你应该避免出现多次滚动的情况。
  • @Sharj - 是的,嗯,这是一个很好的观点。我认为最好的选择是像你说的那样使用库,但是,让我们看看是否有其他人有更好的想法。谢谢你的提及关于它,我没有考虑它:)
猜你喜欢
  • 1970-01-01
  • 2021-09-01
  • 1970-01-01
  • 2020-05-28
  • 1970-01-01
  • 1970-01-01
  • 2016-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多