gpt4 book ai didi

svg - 如何在 Android Xamarin 中将 SVG 文件设置为 ImageView ?

转载 作者:行者123 更新时间:2023-12-04 02:59:46 25 4
gpt4 key购买 nike

我正在使用下面的代码将 svg 文件设置为 ImageView 源。

imageView.SetImageDrawable(Resources.System.GetDrawable(Resource.Drawable.Typogy1));它抛出异常。请建议我如何将 svg 文件设置为 ImageView 。

最佳答案

example James Mundy 的作品非常适合在 xamarin android 中使用 SVG。

但最近在与他聊天时,他说,而且在我看来,在 Android 应用程序中使用 SVG 的最佳方式是使用 Vector Drawables . (比使用任何库都好得多)

矢量可绘制对象易于使用、维护,并且与图像相比非常轻巧,这使它们更加出色。

example如何使用它。

创建 SVG 矢量绘图也非常简单,使用 this

更新:

Vector.xml

<?xml version="1.0" encoding="utf-8" ?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="96dp"
android:width="96dp"
android:viewportHeight="48"
android:viewportWidth="48" >
<group>
<path
android:fillColor="#393939"
android:pathData="M12 36l17-12-17-12v24zm20-24v24h4V12h-4z" />
</group>
</vector>

将此 XML 放在您的资源中的一个文件夹中,例如您的可绘制文件夹或您的布局文件夹,然后按如下方式使用它:

_yourImageView.SetImageResource(Resource.Drawable.Vector);

祝你好运!

如有任何疑问,请回复。

关于svg - 如何在 Android Xamarin 中将 SVG 文件设置为 ImageView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50225996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com