How to use SVG image in ImageView –

Development issue/problem:

Hello, I have an SVG image. How do I add it to the ImageView background?

I’ve tried to use this library, but I have a problem:

01-25 12:19:02.669 27719-27719/com.dvor.androidapp E/AndroidRuntime : FATAL CONCLUSIONS: basic
android.view.InflateException : Binary XML file string #70 : Bloatfout com.caverock.androidsvg.SVGImageViewat android.view.LayoutInflater.createView( android.view.LayoutInflater.createViewFromTag( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate.rInflate( android.view.LayoutInflater.rInflate( on android.view.LayoutInflater.rInflate( on android.view.LayoutInflater.inflate( on android.view.LayoutInflater.inflate ( at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView ( at ( at ( on$1.Run( at android.os.Handler.handleCallback ( at android.os.Handler.dispatchMessage ( at android.os.Looper.loop ( at ( at java.lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect.Method.invoke ( 525) at$ ( 1046) at ( 862) at dalvik.system.NativeStart.main (Indigenous Method) Reason: java.lang.reflect.InvocationTargetException to java.lang.reflect.Constructor.constructNative(Native method)to java.lang.reflect.Constructor.newInstance( android.view.LayoutInflater.createView( android.view.LayoutInflater.createViewFromTag( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate.rInflate( android.view.LayoutInflater.bladder ( at 398) at com.dvor.mobileapp.checkout.onCreateView ( 411) at ( 1786) at$ android.os.Handler.handleCallback( android.os.Handler.dispatchMessage($ at dalvik.system.NativeStart.main (Native Method) Reason: java.lang.NoClassDefFoundError: com.caverock.androidsvg.R$styleableat com.caverock.androidsvg.SVGImageView.init ( at com.caverock.androidsvg.SVGImageView. ( 66) at java.lang.reflection.Constructor.constructNative (Indigenous Method) at java.lang.reflection.Constructor.newInstance ( 417) at android.view.LayoutInflater.createView ( 600) at android.view. LayoutInflater.createView( on android.view.createView( on android.view.LayoutInflater.rInflate( on android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate( android.view.LayoutInflater.rInflate.rInflate( at android.view.LayoutInflater.rInflate( at android.view.LayoutInflater.inflate( at at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView ( at ( at (FragmentManager).java:953) for for for$ android.os.Handler.handleCallback( android.os.Handler.dispatchMessage( android.os.Looper.loop( java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflection.Method.invoke($ dalvik.system.NativeStart.main(Native Method)andt@;at

What did I do?

The first thing I did was add the Gradle addiction:

Compile com.caverock:androidsvg:1.2.1.

Then I changed ImageView to com.caverock.androidsvg.SVGImageView.

Next I added xmls:svgimageview to the root:

This clock.svg is in the asset folder.

How can I solve this problem?

Solution 1:

The new Android Studio has the ability to import the SVG into an XML file, so there is no need to use an external library.

In the drawing, right-click on -> New -> Vector elements -> Local SVG file.

Give here a description of the image

Then normally use it just like the other drawings:


Solution 2:

On newer devices where hardware rendering is enabled by default, software rendering must be explicitly enabled.

imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null) ;

Or add this tag to your xml

android: layerType=software

Solution 3:

To use the svgimageview:svg attribute correctly, an application needs to know its definition. Unfortunately, only the JAR version of the library is currently available and (unlike AAR) the required definition is not properly taken into account when building the application.

Try copying the attrs.xml file from the library source.

in the res/value folder.

I think this should solve your problem.

Solution 4:

Although SVG is a vector image based on XML, Imageview can only display XML (tables with vector drawings). So we need to convert the SVG to XML format. We can do it with Android Vector Asset Studio.

This can be useful to convert SVG, PSD to XML

Solution No 5:

Right click on the res folder,
rendered, select new>>>>Vector Asset>>Local SVG>>>> and save it in xml format.

Good luck!

Related Tags:

android load svg image from url glide,com caverock androidsvg 1.2 1,androidsvg example,picasso cannot load svg,android svg 2019,android imageview set svg programmatically,android:load svg image from url,android svg library,convert svg to vector drawable android studio,the file name must end with xml or png svg,androidsvgloader,android load svg image from url picasso,load svg android github,android dynamic svg,svg in android apps,glide load svg from url,glidetovectoryou,glide to vector,2coffees1team glidetovectoryou v1 0,load svg image using glide android,android svg loader,svg to png,android vector icons xml download,android vector drawable programmatically,png to vector drawable,set svg as background image android,how to use svg image in android,svg to xm,vector image in imageview android,svg to xml,svg converter android,glide download svg image


Leave a Reply

Your email address will not be published. Required fields are marked *