app:cardBackgroundColor这是设置背景颜色
app:cardCornerRadius这是设置圆角大小
app:cardElevation这是设置z轴的阴影
app:cardMaxElevation这是设置z轴的最大高度值
app:cardUseCompatPadding是否使用CompatPadding
app:cardPreventCornerOverlap是否使用PreventCornerOverlap
app:contentPadding 设置内容的padding
app:contentPaddingLeft 设置内容的左padding
app:contentPaddingTop 设置内容的上padding
app:contentPaddingRight 设置内容的右padding
app:contentPaddingBottom 设置内容的底padding
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CardViewActivity">
<android.support.v7.widget.CardView
android:id="@+id/card_view_one"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="5dp">
<TextView
android:id="@+id/info_text_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="CardView1测试"
android:textSize="16sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_view_two"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:cardBackgroundColor="#FFE4B5"
app:cardCornerRadius="5dp">
<TextView
android:id="@+id/info_text_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="CardView2测试"
android:textSize="16sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_view_three"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:cardBackgroundColor="#CAE1FF"
app:cardCornerRadius="5dp">
<TextView
android:id="@+id/info_text_three"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="CardView3测试"
android:textSize="16sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_view_four"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:cardBackgroundColor="#7CCD7C"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
app:cardMaxElevation="5dp">
<TextView
android:id="@+id/info_text_four"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="CardView4测试"
android:textSize="16sp" />
</android.support.v7.widget.CardView>
</LinearLayout>
发表评论 取消回复