CradView的属性和简单使用
文档上是这样介绍的:
A FrameLayout with a rounded corner background and shadow.
cradview是一个带圆角背景和阴影的framelayout。
CardView uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.
CardView在Lollipop(棒棒糖 5.0)上使用高度属性作为阴影,并落回到旧平台上的自定义模拟阴影实现。
XML属性
app:cardBackgroundColor CardView背景颜色。
app:cardCornerRadius CardView转角半径。
app:cardElevation CardViewZ轴的阴影。
app:cardMaxElevation CardView最大Z轴的阴影。
app:cardPreventCornerOverlap 添加填充到CardView在V20之
前,以防止卡的内容和圆角之间的交叉点。
app:cardUseCompatPadding 在API V21 +添加填充,以及有与以前的版本相同的测量。
app:contentPadding 设置CradView内容的padding。
app:contentPaddingBottom 设置CradView内容的底padding。
app:contentPaddingLeft 设置CradView内容的左padding。
app:contentPaddingRight 设置CradView内容的右padding。
app:contentPaddingTop 设置CradView内容的上padding。
使用也特别简单,直接上代码
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/base4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/base140dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/base40dp"
android:gravity="center"
android:textColor="@color/strategy_text_item"
android:textSize="@dimen/base13dp"
android:maxLines="1"
android:ellipsize="end"/>
</LinearLayout>
</android.support.v7.widget.CardView>