CardView

1、CardView简单demo

在这里插入图片描述

依赖

//CardView
implementation 'androidx.cardview:cardview:1.0.0'

//CardView
implementation 'com.android.support:cardview-v7:23.1.1'

布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent">


    <!--  CardView  -->
    <androidx.cardview.widget.CardView
        app:cardBackgroundColor="@android:color/holo_orange_light"
        app:cardCornerRadius="80dp"
        app:cardElevation="10dp"
        ... 
        >

        <!--    cardView内布局    -->
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="card"
                android:textColor="@android:color/white"
                android:textSize="30dp"
                ...
                 />

        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.cardview.widget.CardView>


</androidx.constraintlayout.widget.ConstraintLayout>

2、引入可定制CardView模块

//项目地址
https://gitlab.com/KillerNoBlood-X/cardviewshadowcolor.git

1)配置build.gradle(Project)
在这里插入图片描述

classpath 'com.novoda:bintray-release:0.8.0'
//统一声明配置
ext {
    userOrg = 'hnszyp'
    artifactId = 'cardview'
    groupId = 'com.zyp.cardview'
    uploadName = 'cardview'
    publishVersion = '1.0.1'
    desc = 'CardView change shadow color'
    website = 'https://github.com/zzyyppqq/CardViewShadowColor'
    licences = ['Apache-2.0']
}

2)配置build.gradle(App)
在这里插入图片描述

//cardView
implementation 'androidx.cardview:cardview:1.0.0'

3)同步项目

4)引用Module
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
5)在布局中直接使用YcCardView
在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <!--  YcCardView  -->
    <com.zyp.cardview.YcCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:clickable="true"
        android:focusable="true"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:ycCardCornerRadius="5dp"
        app:ycCardElevation="5dp"
        app:ycCardMaxElevation="5dp"
        app:ycCardPreventCornerOverlap="true"
        app:ycStartShadowColor="@android:color/black">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:gravity="center"
            android:text="Hello World!" />


    </com.zyp.cardview.YcCardView>

</androidx.constraintlayout.widget.ConstraintLayout>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KillerNoBlood

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值