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

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

在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>
效果截图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值