How can i convert this SVG file into a Animated vector drawable for android to show on the activity image.
SVG file
<svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#E31F64">
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)" stroke-width="2">
<circle stroke-opacity=".5" cx="18" cy="18" r="18"/>
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="1s"
repeatCount="indefinite"/>
</path>
</g>
</g>
</svg>
I used some online tools to convert it but they simply creates a vector not the animated vector
Here is the vector
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="38dp"
android:height="38dp"
android:viewportWidth="38"
android:viewportHeight="38">
<group
android:translateX="1"
android:translateY="1">
<path
android:fillType="evenOdd"
android:strokeAlpha=".5"
android:strokeWidth="2"
android:pathData="M 18 0 C 27.941125497 0 36 8.05887450305 36 18 C 36 27.941125497 27.941125497 36 18 36 C 8.05887450305 36 0 27.941125497 0 18 C 0 8.05887450305 8.05887450305 0 18 0 Z" />
<path
android:fillType="evenOdd"
android:strokeWidth="2"
android:pathData="M36 18c0-9.94-8.06-18-18-18" />
</group>
</vector>
How can i create animated out of this to show spinning oval.
Thanks
Use ShapeShifter tool to create Animated Vector Drawable. It is a very basic tool yet fulfills the need.
Related
How to create this layout while fetching data ?
You could have used the Facebook shimmer library for this which is very straightforward.
Facebook Shimmer Library
But for more fine-tuned control you might have to write an animated vector like this.
Source for code Snippet
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<clip-path
android:name="heart"
android:pathData="M 7 3 C 5.465 3 3.922 3.5 2.75 4.7 C 0.407 7.1 0.471 10.8 2.75 13.2 L 12 23 L 21.25 13.2 C 23.529 10.8 23.593 7.1 21.25 4.7 C 18.907 2.4 15.093 2.4 12.75 4.7 L 12 5.5 L 11.25 4.7 C 10.078 3.5 8.536 3 7 3 Z"/>
<path
android:name="path"
android:pathData="M 7 3 C 5.465 3 3.922 3.5 2.75 4.7 C 0.407 7.1 0.471 10.8 2.75 13.2 L 12 23 L 21.25 13.2 C 23.529 10.8 23.593 7.1 21.25 4.7 C 18.907 2.4 15.093 2.4 12.75 4.7 L 12 5.5 L 11.25 4.7 C 10.078 3.5 8.536 3 7 3 Z"
android:fillColor="#ff0000"/>
<group android:name="group">
<path
android:name="shimmer"
android:pathData="M 4 0 L 24 19 L 22 22 L 0 3 Z">
<aapt:attr name="android:fillColor">
<gradient
android:endColor="#FFC500"
android:endX="24"
android:endY="24"
android:startColor="#ED613A"
android:startX="0"
android:startY="0"
android:type="linear" />
</aapt:attr>
</path>
</group>
</vector>
</aapt:attr>
<target android:name="group">
<aapt:attr name="android:animation">
<set>
<objectAnimator
android:propertyName="translateX"
android:duration="700"
android:valueFrom="10"
android:valueTo="-10"
android:valueType="floatType"
android:interpolator="#android:anim/linear_interpolator"/>
<objectAnimator
android:propertyName="translateY"
android:duration="700"
android:valueFrom="-10"
android:valueTo="10"
android:valueType="floatType"
android:interpolator="#android:anim/linear_interpolator"/>
</set>
</aapt:attr>
</target>
</animated-vector>
I'm using material design theme for my toolbar and I'm using a custom instagram icon on one of the tabs. The problem is instead of an icon, only black or white shape of it is being displayed. How do I fix it?
Thank you.
View from different tab
View from instagram tab
Here's my icon XML:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#834fe2"
android:pathData="M15 0H497A15 15 0 0 1 512 15V497A15 15 0 0 1 497 512H15A15 15 0 0 1 0 497V15A15 15 0 0 1 15 0Z" />
<path
android:pathData="M186 108H326A78 78 0 0 1 404 186V326A78 78 0 0 1 326 404H186A78 78 0 0 1 108 326V186A78 78 0 0 1 186 108Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:pathData="M325 256A69 69 0 0 1 187 256A69 69 0 0 1 325 256Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:fillColor="#fbfbfb"
android:pathData="M362 169A19 19 0 0 1 324 169A19 19 0 0 1 362 169Z" />
Here's my styles value:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Here's my colors value:
<resources>
<color name="colorPrimary">#834fe2</color>
<color name="colorPrimaryDark">#fbfbfb</color>
<color name="colorAccent">#52b7f8</color>
<color name="backgroundFragment">#fbfbfb</color>
Modified the vector to remove the unnecessary background. The TabLayout tints the icons depending on the selection state. Your image contained a non-transparent background that was getting tinted together with the image.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:pathData="M186 108H326A78 78 0 0 1 404 186V326A78 78 0 0 1 326 404H186A78 78 0 0 1 108 326V186A78 78 0 0 1 186 108Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:pathData="M325 256A69 69 0 0 1 187 256A69 69 0 0 1 325 256Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:fillColor="#fbfbfb"
android:pathData="M362 169A19 19 0 0 1 324 169A19 19 0 0 1 362 169Z" />
</vector>
I have the ff. vector drawable that I want to repeat based on the progress
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="6dp"
android:viewportHeight="6"
android:viewportWidth="10"
android:width="10dp">
<clip-path android:pathData="M 0 6 L 2.3 0 L 5 0 L 2.7 6 Z" />
<path
android:fillColor="#E60000"
android:pathData="M -5 -5 H 10 V 11 H -5 V -5 Z" />
<clip-path android:pathData="M 4.9 6 L 7.2 0 L 9.9 0 L 7.6 6 Z" />
<path
android:fillColor="#E60000"
android:pathData="M -0.1 -5 H 14.9 V 11 H -0.1 V -5 Z" />
</vector>
However setProgressDrawable stretches the entire drawable.
progressBar.setProgressDrawable(ContextCompat.getDrawable(context, getVectorDrawableRes()));
How do I repeat the above vector drawable instead of stretching it?
I have a vectorDrawable like this:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1668dp"
android:height="1160dp"
android:viewportWidth="1668.0"
android:viewportHeight="1160.0">
<path
android:pathData="M586,394.3 L291.8,394.3 277.7,497.1 270.7,508.3 270.7,650.5 277.7,664.6 293.2,765.9 581.8,765.9"
android:strokeLineCap="butt"
android:strokeColor="#000000"
android:fillColor="#00000000"
android:strokeWidth="5"
android:strokeLineJoin="miter"
android:strokeAlpha="1"/>
<path
android:pathData="M581.6,394.3C581.6,394.3 539.4,473.1 539.4,505.5 539.4,537.9 539.4,611.1 539.4,651.9 539.4,692.7 581.6,765.9 581.6,765.9"
android:strokeLineCap="butt"
android:strokeColor="#000000"
android:fillColor="#00000000"
android:strokeWidth="2"
android:strokeLineJoin="miter"
android:strokeAlpha="1"/>
</vector>
Is there a tool that allow to me to modify the vector using a IDE or something similar ? (Drag & drop ecc)
What I want
I want to be able to draw a Vector Drawable from no path -> target. So for example, draw from nothing to a check mark SVG.
What I've tried
Here is my Vector drawable:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="128dp"
android:width="128dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="done"
android:pathData="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"
android:fillColor="#fff"
android:strokeWidth="1"
android:strokeLineCap="round"
android:strokeColor="#fff"/>
That is just a check mark SVG.
Here is my animation (Which I know is wrong.. :( ). The path data for animating from one vector drawable to another must have the same number of path directions:
<objectAnimator
android:duration="3000"
android:propertyName="pathData"
android:valueFrom="0"
android:valueTo="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"
android:valueType="pathType"
xmlns:android="http://schemas.android.com/apk/res/android" />
And the animated vector (tying together the vector + animation)
<?xml version="1.0" encoding="utf-8"?>
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/ic_done">
<target
android:animation="#animator/ic_disappear"
android:name="opacity"/>
This is wrong as I noted above. How then, do I create an object animator for a SVG to animate from no path to the path I want. This animation is similar to someone drawing the drawable.
As you say, the two paths descriptions have to have the same number of commands and coordinates. Your path is a filled shape, and you can only animate once linearly. So you can't do a two-step down-and-then-up check motion. At least not with a single path morph.
A first simple approach would just be to start from the path start point. That happens to be at the crook of the check mark. So it doesn't look to bad.
<svg width="200" height="200" viewBox="0 0 24 24">
<path d="M0 0">
<animate attributeName="d" attributeType="XML"
from="M9 16.2 L 9 16.2 l 0 0 L 9 16.2 9 16.2 l 0 0 L 9 16.2z"
to="M9 16.2 L 4.8 12 l -1.4 1.4 L 9 19 21 7 l -1.4-1.4 L 9 16.2z"
dur="1s" fill="freeze" />
</path>
</svg>
Or you could start it at the centre point of the corner:
<svg width="200" height="200" viewBox="0 0 24 24">
<path d="M0 0">
<animate attributeName="d" attributeType="XML"
from="M9 17.6 L 9 17.6 l 0 0 L 9 17.6 9 17.6 l 0 0 L 9 17.6z"
to="M9 16.2 L 4.8 12 l -1.4 1.4 L 9 19 21 7 l -1.4-1.4 L 9 16.2z"
dur="1s" fill="freeze" />
</path>
</svg>
Or maybe start with the corner diamond and grow the two "arms" from there.
<svg width="200" height="200" viewBox="0 0 24 24">
<path d="M0 0">
<animate attributeName="d" attributeType="XML"
from="M9 16.2 L 9 16.2 l -1.4 1.4 L 9 19 l 1.4 -1.4 l -1.4-1.4 L 9 16.2z"
to= "M9 16.2 L 4.8 12 l -1.4 1.4 L 9 19 L 21 7 l -1.4-1.4 L 9 16.2z"
dur="1s" fill="freeze" />
</path>
</svg>
You may animate trimPathEnd property from 0 to 1 in duration of your choice instead of animating pathData. So change the propertyName to trimPathEnd and changing the AnimatedVectorDrawable file also suitably. The result is as if the tick is being written now.
Further, if you want a demo read the tutorial "An Introduction to Icon Animation Techniques". There are some interactive demo items in the body of the article.
You may also read about AnimatedVectorDrawable class in android developer site. Though trimPathEnd propertyName is not in the list, it works.