Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – how to init animated vector in kotlin

Posted on November 14, 2022

Solution 1 :

It depends how you apply this Drawable. If it’s set on an ImageView, you can use

(imageView.drawable as? Animatable)?.start()

If it’s the background of a view you can use

(view.background as? Animatable)?.start()

Solution 2 :

Assuming there is an imageview with this vector drawable on it

ImageView imageView = view.findViewById(R.id.animatedImage);

AnimatedVectorDrawable drawable = (AnimatedVectorDrawable)imageView.getDrawable();

drawable.start(); //this starts the animation

drawable.setVisible(true,true); //this also starts the animation from start

Problem :

I followed this tutorial and created my first animated vector in android studio.

my vector is:

<animated-vector xmlns_android="http://schemas.android.com/apk/res/android"
  xmlns_aapt="http://schemas.android.com/aapt"
  android_width="491.4dp"
  android_height="297.83dp"
  android_viewportWidth="491.4"
  android_viewportHeight="297.83"
  android_drawable="@drawable/ic_logo">
  <target android_name="name1">
    <aapt:attr name="android:animation">
      <objectAnimator
        android_duration="2000"
        android_repeatCount="-1"
        android_repeatMode="reverse">
        <propertyValuesHolder android_propertyName="alpha" >
          <keyframe
            android_fraction="0"
            android_value="1f" />
          <keyframe
            android_fraction=".5"
            android_value="0f" />
          <keyframe
            android_fraction="1"
            android_value="1f" />
        </propertyValuesHolder>
      </objectAnimator>
    </aapt:attr>
  </target>
  <target android_name="name2">
    <aapt:attr name="android:animation">
      <objectAnimator
        android_duration="2000"
        android_repeatCount="-1"
        android_repeatMode="reverse">
        <propertyValuesHolder android_propertyName="alpha" >
          <keyframe
            android_fraction="0"
            android_value="1f" />
          <keyframe
            android_fraction=".5"
            android_value="0f" />
          <keyframe
            android_fraction="1"
            android_value="1f" />
        </propertyValuesHolder>
      </objectAnimator>
    </aapt:attr>
  </target>
</animated-vector>

It seems I need to init it in the activity to set animation to work. But I did not find any tutorial about how to init it in Kotlin. Could anyone help me please?

Comments

Comment posted by Tenfour04

FYI, that’s not a tutorial. It’s the official documentation of the class.

Comment posted by weera

Thank you! It wasted all of my day finding a proper solution for it!!!

Comment posted by Tenfour04

Sure thing. You can also cast it to AnimatedVectorDrawable, but Animatable is more versatile because all the different types of animated drawables implement it so your code won’t have to change if you switch to a different type of animated drawable.

READ  [ANSWERED] gradle - building AAR in Android Studio
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress