CardView的用法,CardView是在安卓5.0提出的卡片式控件。
1在gradle文件下添加依赖库:
compile 'com.android.support:cardview-v7:25.3.0'
2使用方法:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardBackgroundColor="#fff"
app:cardCornerRadius="16dp"
app:cardElevation="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:id="@+id/image0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/image1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/image2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
3基本属性:
app:cardBackgroundColor 背景颜色
app:cardCornerRadius 圆角大小
app:cardBackgroundColor 背景颜色
app:cardCornerRadius 圆角大小
app:cardElevation z轴的阴影
app:cardMaxElevation z轴的最大高度值
app:cardUseCompatPadding 是否使用CompatPadding
app:cardPreventCornerOverlap 是否使用PreventCornerOverlap
app:contentPadding 设置内容的padding
app:contentPaddingLeft
app:contentPaddingTop
app:contentPaddingRight
app:contentPaddingBottom