Material Design——CardView的简单使用

作用

卡片布局,有阴影、圆角、在V7包中

添加CardView的依赖:
compile 'com.android.support:cardview-v7:25.0.0'
在XML中使用CardView:
 <!--
        CardView_cardBackgroundColor 设置背景色
        CardView_cardCornerRadius 设置圆角大小
        CardView_cardElevation 设置z轴阴影
        CardView_cardMaxElevation 设置z轴最大高度值
        CardView_cardUseCompatPadding 是否使用CompadPadding
        CardView_cardPreventCornerOverlap 是否使用PreventCornerOverlap
        CardView_contentPadding 内容的padding
    -->

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@color/cardview_light_background"
        app:cardCornerRadius="8dp"
        app:cardElevation="10dp"
        app:cardMaxElevation="12dp"
        app:cardUseCompatPadding="true"
        app:cardPreventCornerOverlap="true"
        app:contentPadding="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Im CardView"/>
    </android.support.v7.widget.CardView>
关于cardUseCompatPadding属性

当值为true时,代表阴影部分可以获得padding:
这里写图片描述
false时,则不会给阴影部分设置padding,保住他的位置:
这里写图片描述

注意

CardView默认是不支持点击的也没有触摸反馈,所以没有波纹效果。要想点击并有反馈

android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"

设置foreground即可。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值