I'd like to use svg-android to load an SVG picture as a layout background. I tried this, but my layout background still white (nothing special in logcat):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.bg);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainLay);
rl.setBackground(svg.createPictureDrawable());
}
What am I doing wrong ?
Well, there was a time when even I was wondering about a similar issue of placing an SVG image on a view.
Here's a demonstration which displays an SVG image in a CustomView in Android:
Here's
CustomView
class:What is important in the above snippet is the line:
Also download and use SVG-Android-2 instead of using its first version.
Apart from that, you can tweak this code to show the SVG as your background image as well. You just have to scale the SVG with a certain factor and then let the
onDraw()
method do its work.Also note that my SVG image is kept in the
assets
folder and so I have used theAssetManager
to load the SVG as shown in the above code.