views:

114

answers:

1

Sorry for the very loud title, but when I try to code a frame-by-frame animation in Eclipse, It gives me a bug. I found something on the internet that says they screwed up in the sdk tutorial documentation but I cannot help but wonder what android:id="selected" means or what should be put in the quotations instead. (I am new to this if you couldn't already tell. :( Sorry.)

Here's the link (delete the space between the h and the t):

h ttp://code.google.com/p/android/issues/detail?id=79

Also, can somebody explain the last part of the frame animation tutorial to me? http://developer.android.com/guide/topics/resources/animation-resource.html#Frame Do you put another code in the filename.Java, and if so, where do you put it? I cannot understand where to put the second code that is not XML... And I think I need to know what the code below is and where it should go...

ImageView fileimage = (ImageView) findViewById  
(R.id.file_image);fileimage.setBackgroundResource
(R.drawable.file_image2);fileAnimation = (AnimationDrawable) 
fileimage.getBackground();fileAnimation.start();

But here is the XML code I used anyway:

 <animation-list android:id="selected" android:oneshot="false">
 <item android:drawable="@drawable/filename" android:duration="200" />
 <item android:drawable="@drawable/filename2" android:duration="200" />
 </animation-list>

Should anything be removed or added from that? I don't know what else to do, because I need to start the animation and have the code for that (1st one) but I don't know where it goes, or if I need another code along with it! Please help?

+1  A: 

This is how I implemented it.

In your main java file you should have something like this.

public class Main extends Activity { 
AnimationDrawable mainanimation;

public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main);

     ImageView mainimage = (ImageView) findViewById(R.id.MainAnim);
     mainimage.setBackgroundResource(R.anim.mainanim);
     mainanimation = (AnimationDrawable) mainimage.getBackground();

So you set the ImageView in your main.xml layout file to the xml that contains the animation (R.id.MainAnim)

Then in your MainAnim.xml (located in res/anim) file you write

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/image1" android:duration="2000" />
<item android:drawable="@drawable/image2" android:duration="2000" />
</animation-list>

Now image1 and image2 will alternate back and forth at 2 seconds each. Also I didn't use andriod:id="selectable".

To recap you need 3 files. Your Main.java, your main.xml layout file, and your mainanim.xml file located in res/anim. Also your 2 images in the drawable folder.

Hope that clears it up a little.

Cameron
It clears it up better but I don't have a mainanim.xml file nor an anim folder. Do you need to make an anim folder in res?I also keep getting the error "id and anim cannot be resolved or is not a field."
Mia
yes you need to create a "anim" folder and xml file that contains the animation code above.
Cameron
Thanks so much Cameron!
Mia
For those who aren't sure how to start the animation, it can be created inside an onTouchEvent such as indicated at the bottom of this android documentation page:http://developer.android.com/guide/topics/graphics/2d-graphics.html#frame-animation
justinl
Also if you want to start the animation automatically without having to touch the screen you can do this.@Override public void onWindowFocusChanged(boolean hasFocus){ mainanimation.start(); }
Cameron