Reputation: 61
I have read in the android developer website this how you can turn sequence of images into animation. But nothing is displayed.neither the image and not the animation.
package org.example.anim;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
public class MainActivity extends Activity {
AnimationDrawable frameAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// Get the background, which has been compiled to an AnimationDrawable
frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
}
public void onWindowFocusChanged()
{
frameAnimation.start();
}
}
Upvotes: 0
Views: 1723
Reputation: 1506
ImageView progressSpinner = (ImageView) findViewById(R.id.progressSpinner);
// Set the background of the image - In this case an animation
// (/res/anim folder)
progressSpinner.setBackgroundResource(R.anim.progress_animation);
// Get the image background and attach the AnimationDrawable to it.
progressAnimation = (AnimationDrawable) progressSpinner.getBackground();
progressAnimation.start();
Move the image from drawable to anim folder and try this code in your onCreate.
Upvotes: 1
Reputation: 5152
if you have added multiple images and also if your spin_animation is list like this:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
then code must work,i think you haven't generated this list properly.also see this link for more help animation drawable
Upvotes: 0