为什么Android错误地渲染了闪屏的矢量绘图?

jdg4fx2g  于 2023-02-10  发布在  Android
关注(0)|答案(1)|浏览(136)

在启动画面中使用下面的矢量绘图,图像呈现完全错误和截断。我尝试改变宽度和高度很多次,但没有区别。其他绘图不存在这个问题:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="35.955055dp"
android:viewportWidth="445"
android:viewportHeight="80">
<path
    android:fillColor="#FF000000"
    android:fillType="nonZero"
    android:pathData="M41.93,79.04C28.39,79.04 18.49,75.2 11.23,68.09C3.98,60.97 -0,51.55 -0,39.56C-0,28.04 3.84,19.05 11.58,11.58C19.32,4.12 29.79,-0 41.86,-0L135.83,-0L135.83,19.32L44.51,19.32C36.28,19.32 31.39,20.86 27.35,24.49C23.3,28.11 21,33.35 21,39.49C21,45.62 23.23,51 27.42,54.69C31.6,58.32 36.69,59.72 45.76,59.72L135.69,59.72L135.69,79.04L41.93,79.04ZM290.42,-0L239.98,52.95L239.98,-0L218.57,-0L169.38,53.02L169.38,-0L147.97,-0L147.97,79.04L169.38,79.04L218.57,26.93L218.57,79.04L241.24,79.04L318.19,-0L290.42,-0ZM419.69,48.42C421.65,48.42 423.32,48.76 424.51,49.81C425.69,50.86 426.39,52.32 426.39,54C426.39,55.74 425.69,57.28 424.51,58.32C423.32,59.37 421.99,59.79 419.69,59.79L318.4,59.79L318.4,79.11L419.69,79.11C434.83,79.11 444.95,69.83 444.95,54.76C444.95,39.69 434.41,30.42 419.27,30.42L340.65,30.42C338.77,30.42 337.16,30.07 336.05,29.09C334.93,28.11 334.3,26.65 334.3,24.98C334.3,23.3 334.93,21.91 336.05,20.93C337.16,19.95 338.49,19.53 340.72,19.53L441.18,19.53L441.18,0.07L340.72,0.07C325.16,0.07 314.63,9.35 314.63,24.42C314.63,39.49 325.16,48.35 340.72,48.35L419.69,48.42Z" />
</vector>

它应该看起来就像一个文本,没有什么特别的,但看看它的外观:

背景:

"androidx.core:core-splashscreen:1.0.0"

    <style name="Theme.AppSplashScreen" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/bground</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
        <item name="postSplashScreenTheme">@style/Theme.App.DayNight</item>
    </style>

如果大小和视口相同,也会发生同样的情况,例如下面这个:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="200dp"
    android:height="56dp"
    android:viewportWidth="200"
    android:viewportHeight="56">
    <path
        android:pathData="M200,0H0V55.91H200V0Z"
        android:fillColor="#EB0045"/>
    <path
        android:pathData="M29.47,42.18C24.19,42.18 20.32,40.68 17.48,37.9C14.65,35.12 13.1,31.44 13.1,26.75C13.1,22.25 14.6,18.74 17.62,15.82C20.64,12.91 24.73,11.3 29.45,11.3H66.15V18.85H30.48C27.27,18.85 25.36,19.45 23.78,20.87C22.2,22.28 21.3,24.33 21.3,26.72C21.3,29.12 22.17,31.22 23.81,32.66C25.44,34.08 27.43,34.63 30.97,34.63H66.1V42.18H29.47ZM126.54,11.3L106.84,31.98V11.3H98.47L79.26,32.01V11.3H70.9V42.18H79.26L98.47,21.82V42.18H107.33L137.39,11.3H126.54ZM177.04,30.21C177.8,30.21 178.46,30.35 178.92,30.76C179.38,31.17 179.65,31.74 179.65,32.39C179.65,33.07 179.38,33.67 178.92,34.08C178.46,34.49 177.94,34.65 177.04,34.65H137.47V42.2H177.04C182.95,42.2 186.9,38.58 186.9,32.69C186.9,26.81 182.79,23.18 176.88,23.18H146.16C145.43,23.18 144.8,23.05 144.37,22.66C143.93,22.28 143.68,21.71 143.68,21.06C143.68,20.4 143.93,19.86 144.37,19.48C144.8,19.09 145.32,18.93 146.19,18.93H185.43V11.33H146.19C140.11,11.33 136,14.95 136,20.84C136,26.72 140.11,30.18 146.19,30.18L177.04,30.21Z"
        android:fillColor="#1D1D1B"/>
</vector>
zdwk9cvp

zdwk9cvp1#

路径数据将基于导入/创建文件时文件的宽度和高度。视区宽度和高度是绘制路径的虚拟画布。
这两者之间会存在差异,从而导致最终结果出现偏差。
我发现this article在理解可绘制对象时很有帮助,它已经有几年的历史了,但我认为基本原理还是一样的。

相关问题