利用CardView实现阴影效果

效果图

核心代码

  1. 添加依赖
implementation 'androidx.cardview:cardview:1.0.0'
  1. 核心xml文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_margin="20dp"
    card:cardCornerRadius="4dp"
    card:cardElevation="10dp"
    card:cardMaxElevation="10dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="望洞庭\n湖光秋月两相和,潭面无风镜未磨。\n遥望洞庭山水翠,白银盘里一青螺。" />
</androidx.cardview.widget.CardView>

完整源代码

https://gitee.com/cxyzy1/shadowByCardView

发布了407 篇原创文章 · 获赞 90 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/yinxing2008/article/details/104846832