美文网首页
Android SVG - 实现渐变边框

Android SVG - 实现渐变边框

作者: 付小影子 | 来源:发表于2024-03-04 17:13 被阅读0次

以往实现渐变边框,是通过layer-list 叠加图层的方式实现,这样实现的边框渐变效果与设计图 总有一些差距,通过svg的方式 实现的边框渐变很自然,与设计图匹配度较高

<?xml version="1.0" encoding="utf-8"?><!--
   Copyright (C) GM Global Technology Operations LLC 2023
   All Rights Reserved.
   GM Confidential Restricted.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="155.72dp"
    android:height="47.39dp"
    android:viewportWidth="155.72"
    android:viewportHeight="47.39">
    <path
        android:name="border"
        android:pathData="M0,0 L155.72,0 L155.72,47.39 H0 L0,0Z"
        android:strokeWidth="2.26"> 渐变边框
        <aapt:attr name="android:strokeColor">
            <gradient
                android:endColor="#FF0"
                android:endX="155.72"
                android:endY="0"
                android:startColor="#F00"
                android:startX="0"
                android:startY="0"
                android:type="linear" />
        </aapt:attr>
    </path>
    <path
        android:name="background"
        android:fillColor="#FF000000"
        android:pathData="M4.85,4.72 H150.87 V42.67 H4.85Z" />
    <path
        android:name="covered_background"
        android:pathData="M4.85,4.72 H150.87 V42.67 H4.85Z">
        <aapt:attr name="android:fillColor"> 渐变背景
            <gradient
                android:endColor="#0FF"
                android:endX="150.87"
                android:endY="0"
                android:startColor="#00F"
                android:startX="4.85"
                android:startY="0"
                android:type="linear" />
        </aapt:attr>
    </path>
</vector>

相关文章

网友评论

      本文标题:Android SVG - 实现渐变边框

      本文链接:https://www.haomeiwen.com/subject/xkkrzdtx.html