<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/content"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dp">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:gravity="center_horizontal">
<XamSvg.SvgImageView
android:id="@+id/icon"
local:svg="res:images.0Password"
android:layout_width="fill_parent"
android:layout_height="40dp" />
</LinearLayout>
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/drawableAutoSize"
android:scaleType="fitCenter"
android:background="#AAD39F" />
</LinearLayout>
我想显示存储在我的App目录中的Svg图像我写了一个代码,显示存储在drawable文件夹中的图像但我想显示来自我的app目录的图像以及图像存储在“Android / data / QR.Android /文件/ Q317664.svg“
using System;
using System.Linq;
using System.Reflection;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using XamSvg;
using Android.Graphics;
namespace QR.Android
{
[Activity(Label = "Activity3",Theme = "@android:style/Theme.Holo.Light.NoActionBar.Fullscreen")]
public class Activity3 : Activity
{
int[] rawIds;
int[] drawableViewIds;
private string[] sharedNames;
int currentId;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.layout1);
//Initialize the cross platform color helper
Setup.InitSvgLib();
//Tells XamSvg in which assembly to search for svg when "res:" is used
var assembly = typeof(AppDomain).GetTypeInfo().Assembly;
XamSvg.Shared.Config.ResourceAssembly = assembly;
//Get all svg resource ids in the raw folder
rawIds = typeof(Resource.Drawable)
.GetFields()
.Where(f => f.IsLiteral)
.Select(f => (int)f.GetRawConstantValue())
.ToArray();
//Get all drawing zones in the current layout
drawableViewIds = typeof(Resource.Id)
.GetFields()
.Where(f => f.IsLiteral && f.Name.StartsWith("drawable"))
.Select(f => (int)f.GetRawConstantValue())
.ToArray();
//Get all svg resources in the shared assembly
sharedNames = assembly.GetManifestResourceNames().Where(n => n.EndsWith(".svg")).OrderBy(n => n).ToArray();
//When clicked, change the svg source in all zones
var contentView = FindViewById(Resource.Id.content);
currentId = currentId + 2;
contentView.Click += (sender, e) =>
{
if (currentId < rawIds.Length)
LoadImageTest(rawIds[currentId]);
// else
// LoadImageTest(sharedNames[currentId-rawIds.Length]);
// currentId = (++currentId)%(rawIds.Length+sharedNames.Length);
};
LoadImageTest(rawIds[currentId++]);
}
void LoadImageTest(int rawId)
{
foreach (var drawableId in drawableViewIds)
{
// if (drawableID != Resource.Id.drawable100)
// continue;
var v = FindViewById<ImageView>(drawableId);
var drawable = SvgFactory.GetDrawable(Resources, rawId);
v.SetImageDrawable(drawable);
}
}
}
}
答案 0 :(得分:0)
尝试免费的Xam.Plugins.Forms.Svg插件〜