android 5.0之cardview

CardView提供了一个默认的elevation(以为CardView的Z轴阴影)和圆角角度

首先我们需要在res/values/attrs中定义属性

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="CardView">
        <attr name="cardBackgroundColor" format="color" />背景色

        <attr name="cardCornerRadius" format="dimension" />圆角度

        <attr name="cardElevation" format="dimension" />阴影的高度

        <attr name="contentPadding" format="dimension" />边界距离内部的距离

        <attr name="contentPaddingLeft" format="dimension" />

        <attr name="contentPaddingRight" format="dimension" />

        <attr name="contentPaddingTop" format="dimension" />

        <attr name="contentPaddingBottom" format="dimension" />
        

    </declare-styleable>
</resources>
 
 
布局文件:
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:CardView="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cardView"
    android:layout_width="500dp"
    android:layout_height="500dp"
    android:layout_gravity="center"
    android:layout_margin="80dp"
    CardView:cardCornerRadius="14dp"
    CardView:cardElevation="8dp"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="TextView in CardView"
        android:textColor="#000000"
        android:textSize="26sp" />

</android.support.v7.widget.CardView>
我们还需要在build.grade文件中配置
compile 'com.android.support:cardview-v7:21.0.+'
配置cardView的步骤如下:file--Project Structure--选中当前module的名称
然后点击右边的dependencies--点击窗口下方的➕号然后选择library dependency--
然后选择com.android.support:cardview-v7:21.0.+点击ok即可完成cardview的配置

效果图:


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值