Shape

前言

本文对shape做个介绍,以及圆角矩形与layer-list

主要元素

gradient – 对应颜色渐变。 startcolor、endcolor就不多说了。 android:angle 是指从哪个角度开始变。
solid – 填充。
stroke – 描边。
corners – 圆角。
padding – 定义内容离边界的距离。与android:padding_left、android:padding_right这些是一个理。

圆角矩形

先抛出结论,圆角矩形的代码如下所示。

<?xml version="1.0" encoding="utf-8"?><!--圆角矩形-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--圆角半径-->
    <corners android:radius="15dp" />
    <!--填充-->
    <solid android:color="@color/white" />
    <!--描边-->
    <stroke
        android:width="1px"
        android:color="@color/black"></stroke>
</shape>

这里有个坑,以前我是不写solid的,觉得没必要,后来发现在4.1.2的手机上出来的shape背景是黑色的,我擦,看来solid必须要写的。

layer-list

有时候可以用多个shape叠加来实现想要的效果,用layer-list

<?xml version="1.0" encoding="utf-8"?>  
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">  
    <item>  
        <shape android:shape="rectangle">  
            <stroke android:color="#00ff00" android:width="1px"></stroke>  
            <solid android:color="#00ffee"></solid>  
        </shape>  
    </item>  
    <item android:bottom="15dp">  
        <shape android:shape="rectangle">  
            <solid android:color="#003f77"></solid>  
        </shape>  
    </item>  
</layer-list>

以上代码就是2个shape的叠加效果如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值