Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获得带有渐变的矢量绘图工具,以便在<;API 24?_Android_Svg_Vector - Fatal编程技术网

Android 如何获得带有渐变的矢量绘图工具,以便在<;API 24?

Android 如何获得带有渐变的矢量绘图工具,以便在<;API 24?,android,svg,vector,Android,Svg,Vector,我正在写一个应用程序,它广泛使用带有渐变标签的矢量绘图 我需要采取哪些步骤,以便具有不同API级别的设备可以使用这些图标,而无需手动将SVG文件转换为不同大小的PNG文件 下面是一个典型的矢量图标,我们在我将它导入android studio后使用它 <vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" a

我正在写一个应用程序,它广泛使用带有渐变标签的矢量绘图

我需要采取哪些步骤,以便具有不同API级别的设备可以使用这些图标,而无需手动将SVG文件转换为不同大小的PNG文件

下面是一个典型的矢量图标,我们在我将它导入android studio后使用它

<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
        android:width="72dp"
        android:height="103dp"
        android:viewportWidth="72.0"
        android:viewportHeight="103.0">
    <path
        android:pathData="M63,40.3L63,26.87C63,12.03 50.91,0 36,0 21.09,0 9,12.03 9,26.87v13.43c-4.97,0 -9,4.01 -9,8.96v44.78C0,98.99 4.03,103 9,103h54c4.97,0 9,-4.01 9,-8.96L72,49.26c0,-4.95 -4.03,-8.96 -9,-8.96zM18,26.87c0,-9.9 8.06,-17.91 18,-17.91 9.94,0 18,8.02 18,17.91v13.43L18,40.3L18,26.87zM63,94.04L9,94.04L9,49.26h54v44.78zM31.5,74.89v5.72c0,2.47 2.02,4.48 4.5,4.48 2.48,0 4.5,-2.01 4.5,-4.48v-5.72c2.68,-1.55 4.5,-4.41 4.5,-7.71 0,-4.95 -4.03,-8.96 -9,-8.96s-9,4.01 -9,8.96c0,3.31 1.82,6.16 4.5,7.71z"
        android:fillType="nonZero">
        <aapt:attr name="android:fillColor">
<gradient 

        android:startY="0.0"
        android:startX="0.0"
        android:endY="103.0"
        android:type="linear"
        android:endX="72.0">
<item android:offset="0.0" android:color="#FFFA8561" />
<item android:offset="1.0" android:color="#FFFC5D5D" />
            </gradient></aapt:attr></path>
</vector>

我注意到像“startX,startY”这样的属性只有API>24。只要能看到梯度,我愿意牺牲这些坐标/方向的精度

我是否可以稍微更改这些属性,以便在所有设备API级别上至少显示一个渐变


感谢尝试使用gradle中的此支持库在较低版本中使用vector drawable。供参考

用于Gradle插件2.0+

   android {
    defaultConfig {
      vectorDrawables.useSupportLibrary = true
                  }
            }
对于Gradle插件1.5或更低版本

      android {
    defaultConfig {
// Stops the Gradle plugin’s automatic rasterization of vectors
   generatedDensities = []
        }
  // Flag notifies aapt to keep the attribute IDs around
   aaptOptions {
     additionalParameters "--no-version-vectors"
   }
   }