设置Button按钮上面圆角下面直角

本文介绍如何使用Android的layer-list及<corners>标签来实现Button的不同圆角效果,特别是顶部圆角底部直角的设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
    <shape>
        <solid
            android:color="#151104"
/>
        <corners
        android:bottomLeftRadius="0dip"
        android:bottomRightRadius="0dip"
        android:topLeftRadius="5dip"
        android:topRightRadius="5dip"
/>
    </shape>
</item>
    <item
        android:bottom="1dp"
        android:right="1dp"
        android:top="1dp"
        android:left="1dp"
>
        <shape>
            <gradient
                android:startColor="#eb6b00"
                android:centerColor="#ef8000"
                android:endColor="#f49500"
                android:type="linear"
                android:angle="90"
                android:centerX="0.5"
                android:centerY="0.5"
/>
            <padding
                android:left="2dp"
                android:top="2dp"
                android:right="2dp"
                android:bottom="2dp"
/>
            <corners
                android:bottomLeftRadius="0dip"
                android:bottomRightRadius="0dip"
                android:topLeftRadius="5dip"
                android:topRightRadius="5dip"
/>
        </shape>
    </item>
</layer-list>

在实现Button圆角的设计上,主要是采用的是layer-list中的<corners>标签,该标签就是用来设置圆角的,在之前使用时,只是知道使用android:radius属性,该属性相当于就是把Button按钮的四个角都设置了圆角,而如果我们想实现上面圆角、下面直角,那么单纯的使用android:radius是不能实现的,因此必须明确的知道其实Button对应的四个角都是有相对应的设置属性的,分别是bottomLeftRadiusbuttonRightRadiustopLeftRadiustopRightRadius四个属性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值