【问题标题】:How to show svg image that is stored in my App directory如何显示存储在我的 App 目录中的 svg 图像
【发布时间】:2016-08-21 17:39:29
【问题描述】:
<?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 图像我编写了一个代码来显示存储在可绘制文件夹中的图像,但我想显示来自我的应用程序目录的图像以及图像存储在“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);
        }
    }


}
}

【问题讨论】:

    标签: android image svg xamarin filepath


    【解决方案1】:

    试试免费的Xam.Plugins.Forms.Svg插件吧~

    【讨论】:

    猜你喜欢
    • 2016-08-19
    • 2020-02-20
    • 2014-08-19
    • 1970-01-01
    • 2014-04-12
    • 2014-09-14
    • 2021-02-02
    • 2016-08-12
    • 1970-01-01
    相关资源
    最近更新 更多