android中的Multiple Section的卡布局设计?

时间:2016-01-20 17:04:46

标签: android android-layout android-recyclerview

以下图片是Google I / O 2015应用的第一页。

enter image description here

我想实现这样的目标。每张卡片中的每个部分,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吗?

1 个答案:

答案 0 :(得分:0)

是的,您可以为每个部分使用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>