动画,如何在运行时添加帧?

时间:2011-07-29 10:33:28

标签: android animation

我们如何在运行时添加帧及其持续时间。例如,如果我们必须从服务器下载一些图像并使它们动画化。

1 个答案:

答案 0 :(得分:1)

public yourClass{
private Timer timer = new Timer();
private long FRAME_RATE = 10;
private ArrayList <Bitmap> sherif; /// this is the array of bitmaps
private ImageView myImageView; //this is the imageview you want to animate
int location = 0;
int numberOfImages = 1000;
private void Animate(){
    timer.schedule(new TimerTask() {
    @Override
    public void run() {
        runOnUiThread(new Runnable() {
             @Override
             public void run() {
                  myImageView.setImageBitmap(sherif.get(location));
             }
        });
        location++;
        if(location==numberOfImages )
             timer.cancel();
    }
    }, 0, 60000/FRAME_RATE );
}