Skip to main content
Título e tags editadas
Link
ramaral
  • 44,7mil
  • 14
  • 60
  • 110

Como reverter a animação de um animated-vector controlar a animação?

Fonte Link

animated-vector controlar a animação

Estou usando o seguinte animated-vector:

<animated-vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt">
    <aapt:attr name="android:drawable">
        <vector
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="50dp"
            android:height="50dp"
            android:viewportWidth="24"
            android:viewportHeight="24">
            <group
                android:name="rotation_group"
                android:pivotX="12"
                android:pivotY="12"
                android:rotation="100">
                <path
                    android:name="path"
                    android:pathData="M 12 20 C 9.791 20 7.791 19.105 6.343 17.657 C 4.895 16.209 4 14.209 4 12 C 4 9.791 4.895 7.791 6.343 6.343 C 7.08 5.606 7.96 5.012 8.938 4.607 C 9.881 4.216 10.915 4 12 4 C 14.209 4 16.209 4.895 17.657 6.343 C 19.105 7.791 20 9.791 20 12 C 20 14.209 19.105 16.209 17.657 17.657 C 16.209 19.105 14.209 20 12 20 M 12 2 C 6.477 2 2 6.477 2 12 C 2 14.761 3.119 17.261 4.929 19.071 C 6.739 20.881 9.239 22 12 22 C 17.523 22 22 17.523 22 12 C 22 6.477 17.523 2 12 2 L 12 2 Z"
                    android:fillColor="#ff000000"
                    android:strokeWidth="1"/>
            </group>
        </vector>
    </aapt:attr>
    <target android:name="rotation_group">
        <aapt:attr name="android:animation">
            <objectAnimator
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:propertyName="rotation"
                android:duration="300"
                android:valueFrom="100"
                android:valueTo="0"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_interpolator"/>
        </aapt:attr>
    </target>
    <target android:name="path">
        <aapt:attr name="android:animation">
            <objectAnimator
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:propertyName="pathData"
                android:duration="300"
                android:valueFrom="M 12 20 C 9.791 20 7.791 19.105 6.343 17.657 C 4.895 16.209 4 14.209 4 12 C 4 9.791 4.895 7.791 6.343 6.343 C 7.08 5.606 7.96 5.012 8.938 4.607 C 9.881 4.216 10.915 4 12 4 C 14.209 4 16.209 4.895 17.657 6.343 C 19.105 7.791 20 9.791 20 12 C 20 14.209 19.105 16.209 17.657 17.657 C 16.209 19.105 14.209 20 12 20 M 12 2 C 6.477 2 2 6.477 2 12 C 2 14.761 3.119 17.261 4.929 19.071 C 6.739 20.881 9.239 22 12 22 C 17.523 22 22 17.523 22 12 C 22 6.477 17.523 2 12 2 L 12 2 Z"
                android:valueTo="M 20 12 C 20 16.418 16.418 20 12 20 C 7.582 20 4 16.418 4 12 C 4 7.582 7.582 4 12 4 C 12.76 4 13.5 4.11 14.2 4.31 C 14.723 3.787 15.247 3.263 15.77 2.74 C 14.61 2.26 13.34 2 12 2 C 6.477 2 2 6.477 2 12 C 2 17.523 6.477 22 12 22 C 17.523 22 22 17.523 22 12 M 7.91 10.08 C 7.44 10.553 6.97 11.027 6.5 11.5 C 8 13 9.5 14.5 11 16 C 14.333 12.667 17.667 9.333 21 6 C 20.53 5.527 20.06 5.053 19.59 4.58 C 16.727 7.443 13.863 10.307 11 13.17 L 7.91 10.08 Z"
                android:valueType="pathType"
                android:interpolator="@android:anim/accelerate_interpolator"/>
        </aapt:attr>
    </target>
</animated-vector>

Ele transformar um circulo e um circulo com check!

Quando o usuário clica, dou inicio a animação:

  public void actionClick(final View view){

        ImageButton bt = ImageButton.class.cast(view);

        if(null != bt.getDrawable()){
            final Animatable animatable = Animatable.class.cast(bt.getDrawable());
            animatable.start();
        }
    }

Mas quando clicar novamente, gostaria de executar a animação de trás para frente, (dando a sensação de unchecked!).

Existe alguma forma para fazer isso?