CardView的使用

CardView的使用

CardView是在安卓5.0引入的卡片式控件。

不使用CardView效果:

使用CardView效果:

一、导包

compile 'com.android.support:cardview-v7:25.3.1'

二、xml添加控件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardBackgroundColor="@color/theme_color"
    app:cardCornerRadius="20dp"
    app:cardElevation="4dp"
    app:cardUseCompatPadding="true"
    app:contentPadding="10dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/user_head"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/user_head"
        android:layout_centerVertical="true"/>

    </RelativeLayout>

</android.support.v7.widget.CardView>

CardView属性说明:

  • app:cardBackgroundColor:设置背景颜色。
  • app:cardCornerRadius:设置圆角大小。
  • app:cardElevation:设置阴影的高度。
  • app:cardMaxElevation:设置阴影的最大高度值。
  • app:cardUseCompatPadding:是否设置UseCompatPadding。v21+的版本和之前的版本仍旧具有一样的计算方式。此为卡片与父容器的边距。
  • app:cardPreventCornerOverlap:是否设置PreventCornerOverlap。在v20和之前的版本中添加内边距,这个属性是为了防止卡片内容和边角的重叠。此为卡片与父容器的边距。
  • app:contentPadding:设置内容的padding。此为卡片与内容的边距。
  • app:contentPaddingLeft:设置内容的左padding。此为卡片与内容的边距。
  • app:contentPaddingTop:设置内容的上padding。 此为卡片与内容的边距。
  • app:contentPaddingRight: 设置内容的右padding。此为卡片与内容的边距。
  • app:contentPaddingBottom:设置内容的底padding。此为卡片与内容的边距。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值