【问题标题】:Android L cards using CardView使用 CardView 的 Android L 卡
【发布时间】:2014-08-12 12:36:22
【问题描述】:

我正在使用新的 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 创建多张卡片?

【问题讨论】:

    标签: android android-5.0-lollipop android-cardview


    【解决方案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>
    

    【讨论】:

    • 啊,缺少链接!我认为 CardView 可以做的不仅仅是将视图包装在卡片中。所以我想如果我想动态创建卡片,我需要将它们包装在 RecyclerView 中。谢谢!
    • @Manoj 请也回答这个问题:stackoverflow.com/questions/36393540/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 2017-12-11
    • 2014-09-01
    • 2020-10-04
    相关资源
    最近更新 更多