CardView继承于Framelayout,比FrameLayout多了 3 个重要的属性
:
card_view:cardElevation,设置卡片的阴影,可以使CardView在z轴方向上有一种抬升的视觉效果,能给用户一种这里是重要信息的视觉感受。对应代码里的方法public void setCardElevation(float radius)。
card_view:cardCornerRadius,设置CardView的圆角。对应代码里的方法public void setRadius (float radius)。
card_view:cardBackgroundColor,设置CardView的背景颜色,这个属性是不会影响阴影card_view:cardElevation的效果的。对应代码里的方法public void setCardBackgroundColor (int color)。
layout示例
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/cv_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
card_view:cardCornerRadius="0dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="10dp"
android:text="Hello World!"
android:textColor="#ffffff"
android:textSize="20sp" />
</android.support.v7.widget.CardView>