Android RelativeLayout设置渐变边框

 

 

 如上图,我们是我们想要的效果,我们实现思路是我们绘制两层shape。

1.shape绘制第一层矩形的填充为渐变色。

2.shape绘制第二层矩形的填充色为白色,然后给第二层上下左右减少边框厚度的尺寸,这样子第一层矩形背景的渐变色就展示出来形成一个边框线。

代码如下:

<layer-list xmlns:andro>

    <item>
        <shape android:shape="rectangle">

            <corners android:radius="4dp"/>

            <gradient
                android:type="linear"
                android:startColor="#ff28efa2"
                android:endColor="#ff0006"
                android:angle="0" />

        </shape>
    </item>

    <item android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="1dp">
        <shape android:shape="rectangle">

            <corners android:radius="4dp"/>

            <solid android:color="@color/white"/>

            <padding android:top="12dp"
                android:bottom="12dp"/>

        </shape>
    </item>
</layer-list>

 

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-01-20
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2022-01-06
  • 2022-02-28
  • 2021-07-07
  • 2022-12-23
  • 2022-02-28
相关资源
相似解决方案