Invalid pathData. Failure occurred at position 65 in FloatingActionButton - android

I am getting an error but it is only on Android Nougat.
This is my fragment_main.xml that contains FloatingActionButton:
<android.support.design.widget.FloatingActionButton
android:id="#+id/btnShowHomeMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"
app:backgroundTint="#color/theme_yellow"
android:layout_marginBottom="20dp"
app:fabSize="normal"
app:borderWidth="0dp"
app:srcCompat="#drawable/ic_menu_main" />
This is my ic_menu_main.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="141dp"
android:height="128dp"
android:viewportWidth="141.4"
android:viewportHeight="128.6">
<path
android:fillColor="#20000000"
android:pathData="M141.4,68.32l-53.03,53.03a25,25 88.59,0 1,-35.36 0l-53.03,-53.03aNaN,NaN NaN,0 1,0 0l42.43,-42.43a40,40 0,0 1,56.57 -0l42.43,42.43ANaN,NaN NaN,0 1,141.4 68.32Z"/>
<path
android:fillColor="#FFF"
android:pathData="M141.38,58.29l-53.03,53.03a25,25 88.59,0 1,-35.36 0l-53.03,-53.03aNaN,NaN NaN,0 1,0 0l42.43,-42.43a40,40 0,0 1,56.57 -0l42.43,42.43ANaN,NaN NaN,0 1,141.38 58.29Z"/>
<path
android:fillColor="#FFffee61"
android:pathData="M0,58.3l49.5,-49.5a30,30 0,0 1,42.4 0l49.5,49.5 -42.4,42.4a40,40 0,0 0,-56.6 0Z"/>
<path
android:fillColor="#FF515151"
android:pathData="M84.89,75.27l-10.61,10.61a5,5 91.17,0 1,-7.07 0l-10.61,-10.61aNaN,NaN NaN,0 1,0 0l10.61,-10.61a5,5 91.17,0 1,7.07 -0l10.61,10.61ANaN,NaN NaN,0 1,84.89 75.27Z"/>
<path
android:fillColor="#FF515151"
android:pathData="M84.82,42.3l-10.61,10.61a5,5 0,0 1,-7.07 0l-10.61,-10.61aNaN,NaN NaN,0 1,0 0l10.61,-10.61a5,5 0,0 1,7.07 -0l10.61,10.61ANaN,NaN NaN,0 1,84.82 42.3Z"/>
<path
android:fillColor="#FF515151"
android:pathData="M67.83,58.27l-10.61,10.61a5,5 90.52,0 1,-7.07 0l-10.61,-10.61aNaN,NaN NaN,0 1,0 0l10.61,-10.61a5,5 0,0 1,7.07 -0l10.61,10.61ANaN,NaN NaN,0 1,67.83 58.27Z"/>
<path
android:fillColor="#FF515151"
android:pathData="M100.89,59.29l-10.61,10.61a5,5 91.17,0 1,-7.07 0l-10.61,-10.61aNaN,NaN NaN,0 1,0 0l10.61,-10.61a5,5 0,0 1,7.07 -0l10.61,10.61aNaN,NaN NaN,0 1,0 0Z"/>
</vector>
I am not sure why it give invalid path data. Anyone knows why?

Nan causes an error which is produced by the converter.
Just replace NaN with some random numbers and it works (try to make sure the number does not cause the vector to change)

Related

how to create Animated layout while data loading data?

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>

Convert SVG into android animated vector drawables

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.

Android ProgressBar setProgressDrawable stretches the vector drawable instead of repeating

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?

How to modify vectorDrawable in Android

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)

AnimatedVectorDrawable empty path to the drawable path

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.

Categories

Resources