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(LayoutInflater.java:626)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate.rInflate(LayoutInflater.java:769)on android.view.LayoutInflater.rInflate(LayoutInflater.java:769) on android.view.LayoutInflater.rInflate(LayoutInflater.java:769) on android.view.LayoutInflater.inflate(LayoutInflater.java:498) on android.view.LayoutInflater.inflate (LayoutInflater.java:398) at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView (ShoppingCart.java:411) at android.support.v4.app.fragment.performCreateView (Fragment.java:1786) at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:953) on android.support.v4.app.fragmentManagerImpl.moveToState(FragmentManager.java:1136)at android.support.v4.app.backStackRecord.run(BackStackRecord.java:739)at android.support.v4.app.fragmentManagerImpl.execPendingActions(FragmentManager.java:1499)at android.support.v4.app.fragmentManagerImpl$1.Run(FragmentManager.java:456) at android.os.Handler.handleCallback (Handler.java:730) at android.os.Handler.dispatchMessage (Handler.java:92) at android.os.Looper.loop (Looper.java:176) at android.app.activityThread.main (ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative (Native Method) at java.lang.reflect.Method.invoke (Method.java: 525) at com.android.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java: 1046) at com.android.os.ZygoteInit.main (ZygoteInit.java: 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(Constructor.java:417)to android.view.LayoutInflater.createView(LayoutInflater.java:600)to android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.bladder (LayoutInflater.java:498) at android.view.LayoutInflater.inflate.java: 398) at com.dvor.mobileapp.checkout.onCreateView (ShoppingCart.java: 411) at android.app.fragment.performCreateView (Fragment.java: 1786) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953)at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)at android.support.v4.app.backStackRecord.run(BackStackRecord.java:739)at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)at android.os.Handler.handleCallback(Handler.java:730)at android.os.Handler.dispatchMessage(Handler.java:92)at android.os.Looper.loop.java:176)at android.app.activityThread.main(ActivityThread.java:5419)at java.lang.reflect.Method.invokeNative.Native.Method.at java.lang.reflect.Method.invoke.Method.java:525)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) at dalvik.system.NativeStart.main (Native Method) Reason: java.lang.NoClassDefFoundError: com.caverock.androidsvg.R$styleableat com.caverock.androidsvg.SVGImageView.init (SVGImageView.java:80) at com.caverock.androidsvg.SVGImageView. (SVGImageView.java: 66) at java.lang.reflection.Constructor.constructNative (Indigenous Method) at java.lang.reflection.Constructor.newInstance (Constructor.java: 417) at android.view.LayoutInflater.createView (LayoutInflater.java: 600) at android.view. LayoutInflater.createView(LayoutInflater.java:600) on android.view.createView(LayoutInflater.java:702) on android.view.LayoutInflater.rInflate(LayoutInflater.java:761) on android.view.LayoutInflater.rInflate.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)at android.view.LayoutInflater.rInflate.rInflate(LayoutInflater.java:769)at android.view.be.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at android.view.LayoutInflater.inflate.java:398) at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView (ShoppingCart.java:411) at android.support.v4.app.Fragment.performCreateView (Fragment.java:1786) at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager).java:953) for android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136) for android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) for android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)at android.os.Handler.handleCallback(Handler.java:730)at android.os.Handler.dispatchMessage(Handler.java:92)at android.os.Looper.loop(Looper.java:176)at android.app.ActivityThread.main(ActivityThread.java:5419)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflection.Method.invoke(Method.java:525)at com.android.os.internal.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)at com.android.os.zygoteInit.main(ZygoteInit.java:862)at dalvik.system.NativeStart.main(Native Method)[email protected];at java.lang.reflect.com.

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:

android:src=http://dnmtechs.com/@drawable/btn_image

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.

https://github.com/BigBadaboom/androidsvg/blob/master/androidsvg/src/main/res/values/attrs.xml

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
https://medium.com/@iamitgupta1994/convert-svg-psd-to-xml-vector-drawable-using-android-vector-asset-studio-8e8ec23d5405

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

Author: gyui

Leave a Reply

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