views:

933

answers:

1

Hi,

I am having trouble applying an animation to a View. I am trying to load the animation from inside the constructor of a CursorAdapter, so I can set it later assign it to certain children in the list.

In the constructor I have :

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

the animation is in my res/anim dir

<?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>

I'm getting an exception : Unknown animation name: animation-list

Help would be much appreciated

Thanks S

A: 

I don't think you load AnimationDrawables via AnimationUtils. AnimationDrawable is a Drawable more than it is an Animation. Try this sample code from the SDK guide.

  ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
  rocketImage.setBackgroundResource(R.anim.rocket_thrust);
  rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
CommonsWare
Hi,Thanks for answering, that is you again isn't it Mark :)The reason I didn't try and use the setBackgroundResource is that I suspect that will cause the animation to run as the background fo my view. I suppose I could get around this by placing an empty ImageView in front of all the other elements and use setBackgroundResource() on that?
Pandalover
You probably do not have to use it as a background, but I think you have to use it as a Drawable, not as an Animation. Try setImageResource() on your ImageView instead of setBackgroundResource(), or something.
CommonsWare