Animating an image

All your problems with Audio, Video and Images.

Animating an image

Postby Teikan » Fri Feb 13, 2009 5:55 pm

Before I get flames, yes, i've seen some of the frame by frame tutorials and snippets here, but i can't seem to get them to work.
I want to make a tiny little animated alert icon, and i've tried using the frame by frame code, but i've failed so far.

the code i'm using is this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <frames id="selected" oneshot="false">
  2.  
  3.     <frame drawable="@drawable/alert_ico" duration="50" />
  4.  
  5.     <frame drawable="@drawable/alert_ico2" duration="50" />
  6.  
  7. </frames>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


and the java basically this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // Load the ImageView that will host the animation and
  2.  
  3.         // set its background to our AnimationDrawable XML resource.
  4.  
  5.         ImageView img = (ImageView)findViewById(R.id.alert_l);
  6.  
  7.         img.setBackgroundResource(R.drawable.alert_ico);
  8.  
  9.  
  10.  
  11.         // Get the background, which has been compiled to an AnimationDrawable object.
  12.  
  13.         AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();    
  14.  
  15.        
  16.  
  17.         // Start the animation (looped playback by default).
  18.  
  19.         frameAnimation.start();
  20.  
  21.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4



This is my layout xml code:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ImageView
  2.  
  3.                         android:id="@+id/alert_btn"                    
  4.  
  5.                 android:layout_width="30px"
  6.  
  7.                 android:layout_height="31px"
  8.  
  9.                 android:layout_alignParentRight="true"
  10.  
  11.                 android:src="@+id/alert_l"
  12.  
  13.                 />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I get no errors compiling but the app just crashes.
If someone can explain what i'm doing wrong i'd be most appreciative, or point me to a tutorial.
Teikan
Freshman
Freshman
 
Posts: 9
Joined: Wed Jan 28, 2009 5:38 pm

Top

Postby Haibane » Wed Feb 25, 2009 10:09 am

Check the logCat for the error, it gives you hint what to fix
User avatar
Haibane
Junior Developer
Junior Developer
 
Posts: 17
Joined: Fri Feb 13, 2009 10:05 am
Location: Klagenfurt, Austria

Postby mdownie » Thu Mar 05, 2009 3:37 pm

I think you are using the wrong ID from your XML layout. Try this code instead:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // Load the ImageView that will host the animation and
  2.  
  3.         // set its background to our AnimationDrawable XML resource.
  4.  
  5.         ImageView img = (ImageView)findViewById(R.id.alert_btn);
  6.  
  7.         img.setBackgroundResource(R.drawable.alert_ico);
  8.  
  9.  
  10.  
  11.         // Get the background, which has been compiled to an AnimationDrawable object.
  12.  
  13.         AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();    
  14.  
  15.        
  16.  
  17.         // Start the animation (looped playback by default).
  18.  
  19.         frameAnimation.start();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

I think you were using the image name for ImageView object instead of the appropriate ImageView ID from the XML.
mdownie
Junior Developer
Junior Developer
 
Posts: 20
Joined: Tue Nov 25, 2008 6:54 pm
Location: Las Vegas

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests