Анимация макета пуста - PullRequest
0 голосов
/ 04 июля 2011

На экран ничего не приходит. Отдельные pngs отображаются нормально. что не так?

<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 Ответ

1 голос
/ 04 июля 2011

Вы должны запустить анимацию

Используйте следующий код в своем коде 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();

        }

    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...