【问题标题】:animation-list not working in Android 5.0 (Lollipop)动画列表在 Android 5.0 (Lollipop) 中不起作用
【发布时间】:2015-03-17 01:24:26
【问题描述】:

我需要一个显示 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 中的动画是否有一些变化?

【问题讨论】:

    标签: android animation android-5.0-lollipop


    【解决方案1】:

    来自 documentation 的 AnimationDrawable,

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

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

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

    【讨论】:

    • 非常感谢!!这似乎是解决方案。但是我还是很好奇为什么直到 Kitkat 版本才需要明确启动动画?
    • AnimationDrawable 中有一个错误,改变可见性总是会启动动画。直到我们开始使用AnimationDrawable 来处理不是进度微调器的东西,例如,这才真正引人注目。 Material 主题中的复选框和单选按钮动画。
    • 非常感谢!!我一直认为它是一个功能:)
    • @alanv 你碰巧有这个问题单的链接吗?
    • 没有公开发行票。
    猜你喜欢
    • 2015-09-04
    • 1970-01-01
    • 2015-06-13
    • 2014-12-25
    • 2015-01-28
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多