Skip to content

Instantly share code, notes, and snippets.

@smartherd
Last active June 14, 2022 14:52
Show Gist options
  • Save smartherd/843bb8bad13979fe0e00851af0ab59bb to your computer and use it in GitHub Desktop.
Save smartherd/843bb8bad13979fe0e00851af0ab59bb to your computer and use it in GitHub Desktop.
AnimatedVectorDrawable
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/avdImage"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.51" />
</androidx.constraintlayout.widget.ConstraintLayout>
<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">
<group
android:name="grouptickcross"
android:pivotX="12"
android:pivotY="12">
<path
android:name="tick"
android:pathData="M 4.8 13.4 L 9 17.6 M 10.4 16.2 L 19.6 7"
android:strokeColor="#999999"
android:strokeWidth="2"
android:strokeLineCap="square"/>
</group>
</vector>
</aapt:attr>
<target android:name="grouptickcross">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="rotation"
android:duration="1000"
android:valueFrom="0"
android:valueTo="180"
android:valueType="floatType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
<target android:name="tick">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="pathData"
android:duration="1000"
android:valueFrom="M 4.8 13.4 L 9 17.6 M 10.4 16.2 L 19.6 7"
android:valueTo="M 6.4 6.4 L 17.6 17.6 M 6.4 17.6 L 17.6 6.4"
android:valueType="pathType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
</animated-vector>
<?xml version="1.0" encoding="utf-8"?>
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_close">
<target
android:name="cross"
android:animation="@animator/close_to_check" />
<target
android:name="groupTickCross"
android:animation="@animator/rotate_close_to_check" />
</animated-vector>
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="pathData"
android:valueFrom="M6.4,6.4 L17.6,17.6 M6.4,17.6 L17.6,6.4"
android:valueTo="M4.8,13.4 L9,17.6 M10.4,16.2 L19.6,7"
android:duration="1000"
android:interpolator="@android:interpolator/fast_out_slow_in"
android:valueType="pathType" />
<!-- Animator to morph path from CLOSE to CHECK -->
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="120dp"
android:height="120dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:name="groupTickCross"
android:pivotX="12"
android:pivotY="12">
<path
android:name="tick"
android:pathData="M4.8,13.4 L9,17.6 M10.4,16.2 L19.6,7"
android:strokeWidth="2"
android:strokeLineCap="square"
android:strokeColor="#999999"/>
</group>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="120dp"
android:height="120dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:name="groupTickCross"
android:pivotX="12"
android:pivotY="12">
<path
android:name="cross"
android:pathData="M6.4,6.4 L17.6,17.6 M6.4,17.6 L17.6,6.4"
android:strokeWidth="2"
android:strokeLineCap="square"
android:strokeColor="#999999"/>
</group>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="rotation"
android:valueFrom="-180"
android:valueTo="0"
android:duration="1000"
android:interpolator="@android:interpolator/fast_out_slow_in" />
<!-- Animator to rotate the vector anti-clockwise -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment