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>