2016-04-27 79 views
-1
<?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> 

我要显示存储在我的应用程序目录SVG图像我写的显示存储在绘制文件夹中图像的代码,但我想说明从图像SVG图像我的应用程序目录,以及图像存储在“安卓/数据/ 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

尝试Xam.Plugins.Forms.Svg的插件,它是免费的〜

+0

我怎样才能使用这个插件,请给我例子。 –

+0

https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/SVG此插件的存储库中有示例 –

相关问题