1 原理就是先画一个大一点的背景,然后再画一个小一点的背景
button_rectangle_red.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 阴影 -->
<item
android:bottom="0px"
android:left="0px"
android:right="0px"
android:top="0px">
<shape android:shape="rectangle">
<!-- 阴影也可以弄成渐变的阴影 -->
<gradient
android:angle="270"
android:endColor="#F6B1B5"
android:startColor="#F6B1B5"
android:type="linear" />
<corners android:radius="40px" />
</shape>
</item>
<!-- 实心内容 bottom、left、right、top的距离就是阴影显示的范围,0就是没有阴影显示的范围-->
<item
android:bottom="3px"
android:left="3px"
android:right="3px"
android:top="3px">
<shape android:shape="rectangle">
<!-- 圆角,想要左右两边都是半圆型,大小就要与按钮的高度一样,我按钮高度为px_60 -->
<corners android:radius="50px" />
<!-- 渐变 ,可以按照属性调出你想要的渐变色 -->
<gradient
android:angle="180"
android:endColor="#CE0008"
android:startColor="#F10009"
android:type="linear"
android:useLevel="true" />
</shape>
</item>
</layer-list>