1

我正在玩新的 Android L SDK,但我不知道如何实现 CardView。好像我错过了一些东西 - 任何建议都非常感谢!

到目前为止,我已将以下声明作为我的活动的一部分:

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:layout_below="@+id/waitingHeader"
    card_view:cardCornerRadius="4dp">

    <LinearLayout
        android:id="@+id/card_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/notificationText"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="hello"/>
        <TextView
            android:id="@+id/notificationTex"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="hello2"/>
    </LinearLayout>
</android.support.v7.widget.CardView>

我天真地希望这会给我两张带有hellohello2的卡片,但是我看到的只是一张带有hello的卡片——第二张卡片不见了。如何使用 CardView 创建多张卡片?

4

1 回答 1

1

将 cardview 想象为 ViewGroup 就像线性布局或相对布局。如果你想要两个卡片视图,那么使用两个卡片视图并将根布局保持为线性或相对布局。

  <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_below="@+id/waitingHeader"
        card_view:cardCornerRadius="4dp">

     <TextView
                android:id="@+id/notificationText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="hello"/>
    </android.support.v7.widget.CardView>

  <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_below="@+id/waitingHeader"
        card_view:cardCornerRadius="4dp">

     <TextView
            android:id="@+id/notificationTex"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="hello2"/>
    </android.support.v7.widget.CardView>
于 2014-08-12T12:41:55.150 回答