hunterp
hunterp

Reputation: 15986

Layout Animation is blank

Nothing comes to the screen. The individual pngs render fine. what is wrong?

<ImageButton
  android:id="@+id/btn_loading"
  android:src="@drawable/loading_animation"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />

And next is the file "loading_animation.xml" :

 <?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="false"
         android:repeatMode="repeat" >
        <item android:drawable="@drawable/load0" android:duration="20" />
        <item android:drawable="@drawable/load1" android:duration="20" />
        <item android:drawable="@drawable/load2" android:duration="20" />
        <item android:drawable="@drawable/load3" android:duration="20" />
        <item android:drawable="@drawable/load4" android:duration="20" />
        <item android:drawable="@drawable/load5" android:duration="20" />
        <item android:drawable="@drawable/load6" android:duration="20" />
        <item android:drawable="@drawable/load7" android:duration="20" />
        <item android:drawable="@drawable/load8" android:duration="20" />
    </animation-list>

Upvotes: 0

Views: 236

Answers (1)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53687

You have to start the animation

Use the following code in your java code

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class Main extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myxml);

        ImageView animation = (ImageView) findViewById(R.id.btn_loading);

        animation.setBackgroundResource(R.drawable.loading_animation);

        AnimationRoutine animationRoutine = new AnimationRoutine();

        Timer t = new Timer(false);

        t.schedule(animationRoutine, 100);

    }

    private class AnimationRoutine extends TimerTask {

        AnimationRoutine() {
        }

        public void run() {

            ImageView img = (ImageView) findViewById(R.id.btn_loading);

            AnimationDrawable frameAnimation = (AnimationDrawable) img
                    .getBackground();

            frameAnimation.start();

        }

    }

}

Upvotes: 1

Related Questions