CardView在设置阴影的效果上来讲,确实是蛮不错的。
但是涉及到变更阴影颜色这个需求,就不是太好操作。
然后就自己描边画了一个阴影效果,分享,支持任何颜色。
效果:

-selector
<? version="1.0" encoding="utf-8"?>
<selector ns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
< -list>
<item android:right="1dp" android:top="2dp">
< -list>
<item>
<shape android:shape="rectangle">
<solid android:color="#15cbf2e0" />
<padding android:bottom="6px" android:left="6px" android:right="6px" android:top="6px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#16cbf2e0" />
<padding android:bottom="4px" android:left="4px" android:right="4px" android:top="4px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#17cbf2e0" />
<padding android:bottom="2px" android:left="2px" android:right="2px" android:top="2px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#18cbf2e0" />
<padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#19cbf2e0" />
<padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#20cbf2e0" />
<padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#21cbf2e0" />
<padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#22cbf2e0" />
<padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#23cbf2e0" />
<padding android:bottom="3px" android:left="2px" android:right="2px" android:top="1px" />
</shape>
</item>
</ -list>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white" />
</shape>
</item>
</ -list>
</item>
</selector>
关于描边的大小什么的,都可以自己设置,颜色也一样。都自己随意。
使用起来也是非常简单,
android:background="@drawable/lay_back"
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
-
“小程序,大生态”:云栖大会阿里巴巴小程序生态联盟成立
2026-05-17栏目: 教程
-
阿里云代码管理平台 Teambition Codeup(行云)亮相,为企业代码安全护航
2026-05-17栏目: 教程
-
广发银行×蚂蚁金服mPaaS:打造下一代移动金融中心
2026-05-17栏目: 教程
-
中国人保健康×蚂蚁金服 联手打造保险服务新标杆
2026-05-17栏目: 教程
-
运维编排场景系列---更新镜像后自动更新伸缩配置镜像
2026-05-17栏目: 教程
