Can't create AnimationDrawable from xml file

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Can't create AnimationDrawable from xml file

Postby dimsuz » Mon Jan 25, 2010 7:17 pm

Heya guys!

I have some custom class BitmapStorage, not attached to any View or whatever - an utility one.
And i have born_animation.xml file which contains <animation-list> with animation frames.

I want to load it as an AnimationDrawable using Resources class (so it would do all the parsing for me), extract Bitmaps and put them to my custom storage class.

The problem i have:

Code: Select all
Resources res = context.getResources();
AnimationDrawable drawable = (AnimationDrawable)res.getDrawable(R.drawable.born_animation);
assertTrue( drawable != null ); <= fails! it's null


WTF? Can someone explain me that? Code compiles fine. All resources are in place.

I tried another way - use ImageView to do the parsing (like described in dev guide)

Code: Select all
ImageView view = new ImageView(context);
view.setBackgroundResource(R.drawable.born_animation);
AnimationDrawable drawable = (AnimationDrawable)view.getBackground();
assertTrue( drawable != null ); <= fails! it's null


Results are the same. it returns the null drawable.

Any hinsts would be greatly appreciated, thanks in advance :)
dimsuz
Freshman
Freshman
 
Posts: 6
Joined: Mon Jan 25, 2010 7:11 pm

Top

Postby dimsuz » Tue Jan 26, 2010 3:04 pm

Yay, I found the cause! :)

It was my bad: I didn't had the proper format of my animation.xml file:

- I didn't use android: namespace in attributes (for some reason i decided it's not required)
- I deleted "duration" attribute in <item> tags

After I fixed these things res.getDrawable() started to return a correct AnimationDrawable instance.

Had to look more precisely at Resources.NotFoundException and it's getCause() to find out what's wrong :)
dimsuz
Freshman
Freshman
 
Posts: 6
Joined: Mon Jan 25, 2010 7:11 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests