【问题标题】:Android Frame by Frame Animation problem on elements in a CursorAdapterCursorAdapter中元素的Android逐帧动画问题
【发布时间】:2009-11-26 12:09:32
【问题描述】:

我在将动画应用到视图时遇到问题。我正在尝试从 CursorAdapter 的构造函数中加载动画,因此我可以稍后将其设置为将其分配给列表中的某些子项。

在我的构造函数中:

shineAnimation = AnimationUtils.loadAnimation(ctx, R.anim.news_list_item_shine);

动画在我的 res/anim 目录中

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
    <item android:drawable="@drawable/shine1" android:duration="200" />
    <item android:drawable="@drawable/shine2" android:duration="200" />
    <item android:drawable="@drawable/shine3" android:duration="200" />
    <item android:drawable="@drawable/shine4" android:duration="200" />
    <item android:drawable="@drawable/shine5" android:duration="200" />
</animation-list>

我遇到了一个例外: 未知动画名称:animation-list

非常感谢您的帮助

谢谢 S

【问题讨论】:

    标签: java android animation


    【解决方案1】:

    我认为您不会通过 AnimationUtils 加载 AnimationDrawablesAnimationDrawableDrawable,而不是 Animation。试试 SDK 指南中的this sample code

      ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
      rocketImage.setBackgroundResource(R.anim.rocket_thrust);
      rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
    

    【讨论】:

    • 嗨,谢谢你的回答,那又是你,不是吗马克:) 我没有尝试使用 setBackgroundResource 的原因是我怀疑这会导致动画作为背景运行我的看法。我想我可以通过在所有其他元素前面放置一个空的 ImageView 并在上面使用 setBackgroundResource() 来解决这个问题?
    • 您可能不必将其用作背景,但我认为您必须将其用作 Drawable,而不是用作动画。在你的 ImageView 上尝试 setImageResource() 而不是 setBackgroundResource() 或其他东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2012-06-08
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多