如何将 svg 图像放入 Xamarin.Android 应用程序的屏幕?
How to put svg image in Xamarin.Android application's screen?
我想要一个图像占据 Xamarin.Android
应用程序屏幕的 40%
。但是由于应用程序必须在 5 and 10 inches
之间的设备上显示良好,所以我放置了一个 .svg
图像以防止像素化,无论屏幕尺寸增加多少。当我 运行 应用程序时,图像没有出现在屏幕上。我的问题是如何将 .svg
图像放入 Xamarin.Android
的应用程序屏幕?这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="100"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--The svg image that has to ocuppy 40% of the screen goes here-->
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="40"
android:layout_width="match_parent"
android:layout_height="0dp">
<ImageView
android:src="@drawable/svg_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />
</LinearLayout>
<!--The rest of the things that have to ocuppy 60% of the screen go here-->
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="60"
android:layout_width="match_parent"
android:layout_height="0dp">
</LinearLayout>
</LinearLayout>
其实Android并没有提供API直接解析.SVG文件的方法
并且有两种解决方案:
1.Use第三方库(如Xamarin.FFImageLoading)。
2.Convert SVG 到 Vector(我认为这比使用任何库都好得多)
您可以使用 this 创建 SVG 矢量绘图,将其转换为矢量绘图后,您将得到一个 vector.xml
,将其放入 Resources/drawable
文件夹中。
那么你可以使用 like
_yourImageView.SetImageResource(Resource.Drawable.Vector);
我想要一个图像占据 Xamarin.Android
应用程序屏幕的 40%
。但是由于应用程序必须在 5 and 10 inches
之间的设备上显示良好,所以我放置了一个 .svg
图像以防止像素化,无论屏幕尺寸增加多少。当我 运行 应用程序时,图像没有出现在屏幕上。我的问题是如何将 .svg
图像放入 Xamarin.Android
的应用程序屏幕?这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="100"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--The svg image that has to ocuppy 40% of the screen goes here-->
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="40"
android:layout_width="match_parent"
android:layout_height="0dp">
<ImageView
android:src="@drawable/svg_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView1" />
</LinearLayout>
<!--The rest of the things that have to ocuppy 60% of the screen go here-->
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="60"
android:layout_width="match_parent"
android:layout_height="0dp">
</LinearLayout>
</LinearLayout>
其实Android并没有提供API直接解析.SVG文件的方法
并且有两种解决方案:
1.Use第三方库(如Xamarin.FFImageLoading)。
2.Convert SVG 到 Vector(我认为这比使用任何库都好得多)
您可以使用 this 创建 SVG 矢量绘图,将其转换为矢量绘图后,您将得到一个 vector.xml
,将其放入 Resources/drawable
文件夹中。
那么你可以使用 like
_yourImageView.SetImageResource(Resource.Drawable.Vector);