[英]Why vector images behave weirdly with API < 24 Android Studio
I was trying to make a custom vector image for my android app, I figuered out a good pathData and got the correct result in the Preview window, also got the correct result when I ran the app in different phones except for the one with Android 6.0 ( API<23 )!我试图为我的 android 应用程序制作一个自定义矢量图像,我找到了一个很好的 pathData 并在预览window 中得到了正确的结果,当我在不同的手机中运行该应用程序时也得到了正确的结果,除了带有 ZE84E30B0390CDB66DAB486DB7 的手机。 ( API<23 )!
Here is the vector image XML file:这是矢量图像 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="100dp"
android:viewportWidth="400"
android:viewportHeight="200">
<path
android:fillColor="#0277BD"
android:pathData="M0,200 L70,200 A130,130 0 0,1 118,99 L74,45 A200,200 0 0,0 0,200 Z"
android:strokeWidth="1"
android:strokeColor="#000" />
<path
android:fillColor="#4CAF50"
android:pathData="M74,45 L118,99 A130,130 0 0,1 200,70 L200,0 A200,200 0 0,0 74,45 Z"
android:strokeWidth="1"
android:strokeColor="#000" />
<path
android:fillColor="#FFC107"
android:pathData="M200,0 L200,70 A130,130 0 0,1 265,87.4 L300,26.8 A200,200 0 0,0 200,0 Z"
android:strokeWidth="1"
android:strokeColor="#000" />
<path
android:fillColor="#FF5722"
android:pathData="M300,26.8 L265,87.4 A130,130 0 0,1 312.6,135 L373.2,100 A200,200 0 0,0 300,26.8 Z"
android:strokeWidth="1"
android:strokeColor="#000" />
<path
android:fillColor="#DB1C1C"
android:pathData="M373.2,100 L312.6,135 A130,130 0 0,1 330,200 L400,200 A200,200 0 0,0 373.2,100 Z"
android:strokeWidth="1"
android:strokeColor="#000" />
</vector>```
Here is the Preview
[Preview][1]
Here is the output on Android 6.0 phone
[Output][2]
[1]: https://i.stack.imgur.com/3mTaO.png
[2]: https://i.stack.imgur.com/xXTnv.png
If you have.svg file of picture, upload it in Android Studio by clicking right mouse button on drawable folder in Android Studio Project (Alt+1), choose New and Vector Asset .如果你有.svg图片文件,上传到Android Studio,在Android Studio Project (Alt+1)的drawable文件夹上点击鼠标右键,选择New and Vector Asset 。 In Asset Type select Local file (SVG, PSD) , browse to your.svg file and let Android Studio convert it into.xml. In Asset Type select Local file (SVG, PSD) , browse to your.svg file and let Android Studio convert it into.xml.
You'll give it name and then you can find it in drawable folder or call it by name in.java/.kt or in.xml layout file.你会给它起名字,然后你可以在drawable 文件夹中找到它,或者在 in.java/.kt 或 in.xml 布局文件中调用它。
Hope it helps希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.