Tuesday, 17 February 2015

how to show svg images from the web url in android ?

relatvelayout = (RelativeLayout) findViewById(R.id.relatvelayout);
ImageView svgImageView = new ImageView(this);
relatvelayout.addView(svgImageView, new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
try{

   final URL urls = new URL("http://upload.wikimedia.org/wikipedia/commons/e/e8/Svg_example3.svg");
        HttpURLConnection urlConnection = (HttpURLConnection) urls.openConnection();
        InputStream inputStream = urlConnection.getInputStream();
        SVG svg = SVGParser. getSVGFromInputStream(inputStream);
        Drawable drawable = svg.createPictureDrawable();
        svgImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        svgImageView.setImageDrawable(drawable);

}catch(Exception e){

e.printStackTrace();
}

No comments:

Post a Comment