1. 在build.gradle中添加依赖库
compile 'com.android.support:cardview-v7:24.2.1'
2. 布局中使用
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_white">
<android.support.v7.widget.CardView
android:id="@+id/card_channel_item"
android:layout_width="match_parent"
android:layout_height="@dimen/px350"
android:layout_marginBottom="@dimen/px24"
android:layout_marginLeft="@dimen/px24"
android:layout_marginRight="@dimen/px24"
android:background="@color/white"
app:cardCornerRadius="@dimen/px8"
app:cardElevation="@dimen/px10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.yiban.caesar.View.CircleImageView
android:id="@+id/iv_circle_head"
android:layout_width="@dimen/px150"
android:layout_height="@dimen/px150"
android:layout_marginBottom="@dimen/px54"
android:layout_marginLeft="@dimen/px40"
android:layout_marginRight="@dimen/px40"
android:layout_marginTop="@dimen/px54"
android:src="@drawable/ic_launcher"
app:civ_border_color="@color/colorAccent"
app:civ_border_width="@dimen/px4"/>
<TextView
android:id="@+id/tv_item_name"
style="@style/text_32px_33"
android:layout_marginTop="@dimen/px80"
android:layout_toRightOf="@+id/iv_circle_head"
android:text="name"/>
<TextView
android:id="@+id/tv_item_level"
style="@style/text_24px_66"
android:layout_alignBottom="@+id/tv_item_name"
android:layout_marginLeft="@dimen/px24"
android:layout_toRightOf="@+id/tv_item_name"
android:text="经纪人等级"/>
<TextView
android:id="@+id/tv_item_company"
style="@style/text_28px_33"
android:layout_alignLeft="@+id/tv_item_name"
android:layout_below="@+id/tv_item_name"
android:layout_marginTop="@dimen/px26"
android:text="公司"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/px90"
android:layout_alignParentBottom="true"
android:layout_marginLeft="@dimen/px30"
android:layout_marginRight="@dimen/px30"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/rl_share_card"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_fxmp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/dev_icon_fxmp"/>
<TextView
style="@style/text_28px_33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/px20"
android:layout_toRightOf="@+id/iv_fxmp"
android:layout_weight="1"
android:text="分享名片"/>
</RelativeLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/px10"
android:layout_marginTop="@dimen/px10"
android:background="@color/line_gray"/>
<RelativeLayout
android:id="@+id/rl_to_chat"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="@+id/iv_lyl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/dev_icon_lyl"/>
<TextView
style="@style/text_28px_33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/px20"
android:layout_toRightOf="@+id/iv_lyl"
android:layout_weight="1"
android:text="聊一聊"/>
</RelativeLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/px10"
android:layout_marginTop="@dimen/px10"
android:background="@color/line_gray"/>
<RelativeLayout
android:id="@+id/rl_channel_call"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_ddl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/dev_icon_ddh"/>
<TextView
style="@style/text_28px_33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/px20"
android:layout_toRightOf="@+id/iv_ddl"
android:layout_weight="1"
android:text="打电话"/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/px88"
android:layout_marginLeft="@dimen/px30"
android:layout_marginRight="@dimen/px30"
android:background="@color/line_gray"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
3. 就可以使用了
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cardview的一些属性 :
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
app:cardElevation="0dp" 设置阴影大小
app:cardUseCompatPadding="false" 取消阴影