【发布时间】:2015-06-27 01:12:19
【问题描述】:
我在布局的图像视图中加载了一个 png 文件。然后我有一个 svg 图像,我需要在该 png 图像之上渲染。
请提出任何可能的方法。
如果您对我的问题有任何澄清,请告诉我。
SVG svg1 = SVGParser.getSVGFromResource(getResources(), R.raw.svg_image1);
Drawable resID1 = svg1.createPictureDrawable();
SVG svg2 = SVGParser.getSVGFromResource(getResources(), R.raw.svg_image2);
Drawable resID2 = svg2.createPictureDrawable();
SVG svg3 = SVGParser.getSVGFromResource(getResources(), R.raw.svg_image3);
Drawable resID3 = svg3.createPictureDrawable();
Drawable mainImage = this.getResources().getDrawable(R.drawable.main_image);
LayerDrawable ld = new LayerDrawable(new Drawable[]{mainImage, resID1, resID2, resID3});
ld.setLayerInset(1, 1, 1, 1, 1);
ImageView imageView = (ImageView) findViewById(R.id.img1);
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
imageView.setImageDrawable(ld);
【问题讨论】:
-
您需要一个库来将 SVG 文件呈现为图像。然后简单地叠加 2 个图像。 Here我回答了如何叠加2张图片。
-
我们这个例如:
https://code.google.com/p/svg-android/然后使用LayerDrawable覆盖两个Drawables -
我已经编辑了你的标题。请参阅Should questions include “tags” in their titles?,其中的共识是“不,他们不应该”。
-
谢谢pskink。我使用了两个覆盖在 png 文件上的 svg 文件。但我无法将 png 文件作为背景查看。我尝试过不透明度的概念。没有任何效果。 2个svg文件是图片可绘制格式,png是位图可绘制格式。
-
我发表了一条评论,并为此链接了一个答案。
标签: android svg png android-animation androidsvg