android中的平铺集动画

android中的平铺集动画,android,animation,Android,Animation,[编辑]代码更改。 有一套24框的瓷砖。 我怎样才能从一个接一个的动态动画? 我试过这个,但没有任何效果: ImageView image = (ImageView)findViewById(R.id.imageView); Bitmap TileSet = BitmapFactory.decodeResource(getResources(), R.drawable.Image); Bitmap frame = Bitmap.createBitmap(256, 128, Bitmap.Conf

[编辑]代码更改。

有一套24框的瓷砖。 我怎样才能从一个接一个的动态动画? 我试过这个,但没有任何效果:

ImageView image = (ImageView)findViewById(R.id.imageView);
Bitmap TileSet = BitmapFactory.decodeResource(getResources(), R.drawable.Image);
Bitmap frame = Bitmap.createBitmap(256, 128, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(frame);

for (int i = 10, width, height; i < 24; i++) {
  width = i/4;
  height = i%4;
  try {
    Thread.sleep(125);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  canvas.drawBitmap(TileSet
                    , new Rect(256 * width, 128 * height
                                , 256 * (width+1), 128 * (height+1))
                    , new Rect(0, 0, image.getWidth(), image.getHeight())
                    , null);
  image.setImageBitmap(frame);
}
ImageView image=(ImageView)findviewbyd(R.id.ImageView);
位图TileSet=BitmapFactory.decodeResource(getResources(),R.drawable.Image);
位图帧=Bitmap.createBitmap(256、128、Bitmap.Config.ARGB_8888);
画布=新画布(框架);
对于(int i=10,宽度,高度;i<24;i++){
宽度=i/4;
高度=i%4;
试一试{
睡眠(125);
}捕捉(中断异常e){
e、 printStackTrace();
}
canvas.drawBitmap(平铺集)
,新矩形(256*宽,128*高
,256*(宽+1),128*(高+1))
,新的矩形(0,0,image.getWidth(),image.getHeight())
,空);
设置图像位图(帧);
}
我们的想法是将此动画绘制一次,然后永远关闭此活动。这就是为什么我不能理解如何在这里使用onDraw函数

[已编辑2]

private void startAnimating() {
Bitmap frame;
long beginLoopTime = 0;
for (int i = 0, width, height; i < 32; i++) {
  width = i/8;
  height = i%8;

  while(System.currentTimeMillis() - beginLoopTime < DURATION) {}

  frame = Bitmap.createBitmap(TileSet, 256 * width, 128 * height, 256, 128);

  final BitmapDrawable temp = new BitmapDrawable(getResources(), frame);

  image.post(new Runnable() {
    @Override
    public void run() {
      image.setBackground(temp);
      image.invalidate();
    }
  });

  beginLoopTime = System.currentTimeMillis();
}
private void startAnimating(){
位图帧;
长beginLoopTime=0;
对于(int i=0,宽度,高度;i<32;i++){
宽度=i/8;
高度=1%8;
而(System.currentTimeMillis()-beginLoopTime
}

此函数仅绘制最后一帧。
我尝试使用onWindowFocusChanged…效果相同。

您可以使用xml创建帧动画,并在活动中加载动画。或者创建一个runnable并在UI线程内运行它


如何创建一个可运行并更改其中的帧?整个活动仅用于一个动画,之后将不再使用。这就是为什么我认为没有必要使用新的线程。或者你能给我更完整的描述或链接吗?