以往實現(xiàn)漸變邊框话瞧,是通過layer-list 疊加圖層的方式實現(xiàn)逊脯,這樣實現(xiàn)的邊框漸變效果與設(shè)計圖 總有一些差距究飞,通過svg的方式 實現(xiàn)的邊框漸變很自然埃疫,與設(shè)計圖匹配度較高
<?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>