布局动画为空白

时间:2011-07-04 05:33:20

标签: android android-layout

屏幕上没有任何内容。个人png渲染得很好。怎么了?

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

接下来是文件“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>

1 个答案:

答案 0 :(得分:1)

您必须 启动动画

在java代码中使用以下代码

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();

        }

    }

}