动画列表在Android 5.0(Lollipop)中不起作用

时间:2015-03-16 09:34:13

标签: android animation android-5.0-lollipop

我需要一个简单的动画,显示3点加载。所以我创建了3个图像,将其添加到动画列表并将其设置为imageview。直到kitkat工作正常,但在将我的操作系统更新到Lollipop之后,动画似乎不起作用。

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >

<item
    android:drawable="@drawable/one_dot"
    android:duration="500"/>
<item
    android:drawable="@drawable/two_dot"
    android:duration="500"/>
<item
    android:drawable="@drawable/three_dot"
    android:duration="500"/>

</animation-list>

这就是它设置为imageView的方式

   <ImageView
        android:id="@+id/dotsLoadingView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/loadingText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:src="@drawable/dots_loading" />

Android 5.0 Lollipop中的动画有什么变化吗?

1 个答案:

答案 0 :(得分:16)

来自AnimationDrawable的documentation

  

创建逐帧动画的最简单方法是在XML文件中定义动画,放置在res/drawable/文件夹中,并将其设置为View对象的背景。然后,调用start()来运行动画。

您需要调用start()来运行动画。

final ImageView myView = (ImageView) findViewById(R.id.dotsLoadingView);
((Animatable) myView.getDrawable()).start();