这样的方法是通过层叠几个图片实现边框效果。

在res目录下的drawable目录下(没有就新建)建一个xml文件选layer-list。

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:andro >

    <!--
         与顺序有关。最外层一定要放在最前面。最里层放在里面,
         不然会被遮挡。也与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:andro
    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:
        android:layout_width="match_parent"
        android:layout_height="137dp"
        android:background="@drawable/buttonl"
        android:text="button01" />

</LinearLayout>
效果截图:

第三章,设置button边框(Android)


相关文章:

  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-10-19
  • 2022-02-17
  • 2021-07-30
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案