这种方法是通过层叠几个图片实现边框效果。
在res文件夹下的drawable文件夹下(没有就新建)建一个xml文件选layer-list。
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!--
与顺序有关,最外层一定要放在最前面,最里层放在里面,
不然会被遮挡,也与item中设置的值大小有关系
-->
<!-- 最外层 -->
<item>
<shape>
<solid android:color="#1e90ff" />
</shape>
</item>
<!-- 中间层 -->
<item
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp">
<shape>
<solid android:color="#ffffff" />
</shape>
</item>
<!-- 最里层 -->
<item
android:bottom="30dp"
android:left="30dp"
android:right="30dp"
android:top="30dp">
<shape>
<solid android:color="#bebebe" />
</shape>
</item>
</layer-list>
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal"
>
<Button
android:id="@+id/main_button"
android:layout_width="match_parent"
android:layout_height="137dp"
android:background="@drawable/buttonl"
android:text="button01" />
</LinearLayout>
效果截图: