0
点赞
收藏
分享

微信扫一扫

Android 显示SVG格式图片


说明

使用的开源库​​AndroidSVG​​​。
​​​github 地址​​​
也可以​​点此下载jar包​​

步骤

  1. 将下载的jar文件添加到工程。
  2. 将svg格式图片放到assets目录。
  3. 使用代码添加view显示或者在xml文件配置显示。

示例代码

代码中添加view

SVG svg = null;
try {
svg = SVG.getFromAsset(getAssets(), "test.svg");
} catch (Exception e) {
e.printStackTrace();
}

RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl_root);

SVGImageView view = new SVGImageView(this);
view.setSVG(svg);
rl.addView(view, new RelativeLayout.LayoutParams(800, 600));

xml中添加view,测试报错。。。还是贴上。

<com.caverock.androidsvg.SVGImageView
xmlns:svg="http://schemas.android.com/apk/res-auto"
android:layout_width="100dp"
android:layout_height="50dp"
svg:svg="filename.svg"/>

后记

  1. svg图片的显示比例应和原图差不多。否则会按原图比例显示。scaleType貌似不管用。


举报

相关推荐

0 条评论