Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation-list (animationDrawable) autostart

Is it possible to set animation-list drawable to autostart after inflating from XML without using AnimationDrawable.start()?

My animation-list:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
    <item android:drawable="@drawable/download_light" android:duration="200" />
    <item android:drawable="@drawable/download20" android:duration="200" />
    <item android:drawable="@drawable/download40" android:duration="200" />
    <item android:drawable="@drawable/download60" android:duration="200" />
    <item android:drawable="@drawable/download80" android:duration="200" />
    <item android:drawable="@drawable/download_on" android:duration="300" />
</animation-list>
like image 548
neworld Avatar asked Jan 08 '13 17:01

neworld


2 Answers

you can set AnimationDrawable as ProgressBar android:indeterminateDrawable, then AnimationDrawable will start automatically when ProgressBar become visible

    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:minWidth="1dp"
        android:minHeight="1dp"
        android:maxWidth="10000dp"
        android:maxHeight="10000dp"
        android:indeterminate="true"
        android:indeterminateBehavior="repeat"
        android:indeterminateDrawable="@drawable/indeterminate_progess_animation_drawable" />
like image 148
Yessy Avatar answered Sep 25 '22 23:09

Yessy


After test on some device with different API, I found:
Without using AnimationDrawable.start()

  • In almost devices animation-list will not auto start
  • In few devices (almost device 4.4) will auto start

Therefore, I think we should always use AnimationDrawable.start() and AnimationDrawable.stop() for start/stop animation

like image 21
Linh Avatar answered Sep 21 '22 23:09

Linh