I am having a play with the new Android L SDK and I can't figure out how to implement CardView. Seems like I'm missing something - any advice is very much appreciated!
So far I have the following declared as part of my activity:
<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>
Naively I was hoping that would give me two cards with hello and hello2 however all I see is a single card with hello - the second card is missing. How can I create multiple cards using CardView?
Think of cardview as ViewGroup Like linear layout or Relative layout. If you want two cardview then use two cardview and keep root layout as Linear or Relative Layout.
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.