Android CardView属性和使用总结

本文介绍了Android CardView的使用,包括如何添加依赖、CardView的属性,特别是点击水波纹(Ripple)效果的实现。在5.0及以上版本,可通过设置foreground属性实现Ripple,而在5.0以下版本则需使用selector。同时,文章还讨论了CardView的Z轴阴影padding、圆角覆盖和lift-on-touch交互效果的设置方法。
摘要由CSDN通过智能技术生成

CardView的使用:

如果不知道要依赖的cardview的版本,可以通过以下操作添加依赖:

1、鼠标放在要添加依赖的module上,右键选择Open Module Settings,如图1:

图1

 2、在Module Settings中按图2进行操作:

图2

 点击OK后等待building完成即可。

CardView属性介绍:

Google官方对CardView的一句话解释为:带有阴影背景和圆角的FrameLayout。

下面是CardView的一些常用属性:

<resources>
    <declare-styleable name="CardView">
        <!-- Background color for CardView. -->
        <!-- 设置背景色 -->
        <attr name="cardBackgroundColor" format="color" />
        <!-- Corner radius for CardView. -->
        <!-- 设置圆角大小 -->
        <attr name="cardCornerRadius" format="dimension" />
        <!-- Elevation for CardView. -->
        <!-- 设置Z轴阴影高度 -->
        <attr name="cardElevation" format="dimension" />
        <!-- Maximum Elevation for CardView. -->
        <!-- 设置Z轴阴影最大高度 -->
        <attr name="cardMaxElevation" format="dimension" />
        <!-- Add padding in API v21+ as well to have the same measurements with previous versions. -->
        <!-- 设置内边距,v21+的版本和之前的版本仍旧具有一样的计算方式 -->
        <attr name="cardUseCompatPadding" format="boolean" />
        <!-- Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners. -->
        <!-- 在v20和之前的版本中添加内边距,这个属性是为了防止卡片内容和边角的重叠 -->
        <attr name="cardPreventCornerOverlap" format="boolean" />
        <!-- 下面是卡片边界距离内部的距离-->
        <!-- Inner padding between the edges of the Card and children of the CardView. -->
        <attr name="contentPadding" format="dimension" />
        <!-- Inner padding between the left edge of the Card and children of the CardView. -->
        <attr name="contentPaddingLeft" format="dimension" />
        <!-- Inner padding between the right edge of the Card and children of the CardView. -->
        <attr name="contentPaddingRight" format="dimension" />
        <!-- Inner padding between the top edge of the Card and children of the CardView. -->
        <attr name="contentPaddingTop" format=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值