So, I’m new to programming with android and one of the first thing I’m trying to do is create a basic animation that starts on its own. Nothing complicated, just a looping animation. I am trying to stick with frame-by-frame because it seems the most basic and easiest to understand. I have looked at many tutorials/websites/videos (including the android dev sites) on how to do this and can’t figure out what I’m doing wrong. I’m sure I have a simple logic error somewhere. Below is my posted code. Can someone help me out? Thank you for the help! (Also, as a side note this is specifically running on a NookColor emulator, according to Nook Developer site, the nook runs the latest android. Unfortunately the Nook site gives no tutorials or anything useful, only the same links to Android developers.)
//main class
public class WallpaperActivity extends Activity {
AnimationDrawable animSequence;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView animImg = (ImageView) findViewById(R.id.animatepic);
animImg.setBackgroundResource(R.drawable.animation);
animSequence = (AnimationDrawable) animImg.getBackground();
}
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
animSequence.start();
}
}
//animation.xml class ( << this is not my main.xml class)
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/animatepic" android:oneshot="false" >
<item android:drawable="@drawable/a" android:duration="200" />
<item android:drawable="@drawable/b" android:duration="200" />
<item android:drawable="@drawable/c" android:duration="200" />
<item android:drawable="@drawable/d" android:duration="200" />
<item android:drawable="@drawable/e" android:duration="200" />
<item android:drawable="@drawable/f" android:duration="200" />
<item android:drawable="@drawable/g" android:duration="200" />
<item android:drawable="@drawable/h" android:duration="200" />
<item android:drawable="@drawable/i" android:duration="200" />
<item android:drawable="@drawable/j" android:duration="200" />
<item android:drawable="@drawable/k" android:duration="200" />
<item android:drawable="@drawable/l" android:duration="200" />
<item android:drawable="@drawable/m" android:duration="200" />
<item android:drawable="@drawable/n" android:duration="200" />
<item android:drawable="@drawable/o" android:duration="200" />
</animation-list>
Did you say what error you were getting?
In any case, your code example seems to have been updated.
Here is its zip file you can download.