Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android的Canvas onDraw()中设置位图动画?_Android_Animation_Android Canvas_Android Animation_Bitmapfactory - Fatal编程技术网

如何在Android的Canvas onDraw()中设置位图动画?

如何在Android的Canvas onDraw()中设置位图动画?,android,animation,android-canvas,android-animation,bitmapfactory,Android,Animation,Android Canvas,Android Animation,Bitmapfactory,有人能帮我在画布上的两个位图上设置动画吗? 我有两个位图“位图1”和“位图2” 我想显示“位图1”,然后以500ms的间隔显示“位图2”,然后再次显示位图1,依此类推。。。 我希望任何方法都能做到这一点,但不要使用Thread.sleep(500) 提前感谢…在线程中尝试以下内容: long lastBitmapSwitchMillis = System.currentTimeMillis(); //Saves system time from last bitmap switch int

有人能帮我在画布上的两个位图上设置动画吗? 我有两个位图
“位图1”
“位图2”

我想显示
“位图1”
,然后以
500ms的间隔显示
“位图2”
,然后再次显示
位图1
,依此类推。。。 我希望任何方法都能做到这一点,但不要使用
Thread.sleep(500)


提前感谢…

在线程中尝试以下内容:

long lastBitmapSwitchMillis = System.currentTimeMillis();   //Saves system time from last bitmap switch
int currentBitmap = 1;   //1 = bitmap1, 2 = bitmap2
int bitmapInterval = 500;   //Interval between bitmap switches

while (running) {

     //Switches bitmap after interval
     if (System.currentTimeMillis() >= lastBitmapSwitchMillis + bitmapInterval) {
          lastBitmapSwitchMillis = System.currentTimeMillis();   //Save current time of bitmap switch
          if (currentBitmap == 1) {
               currentBitmap = 2;
          }
          else if (currentBitmap == 2) {
               currentBitmap = 1;
          }
     }

     //Render appropriate bitmap
     if (currentBitmap = 1) {
          canvas.drawBitmap(bitmap1, x, y, paint);   //x and y are bitmap's location,
     }
     else if (currentBitmap = 2) {
          canvas.drawBitmap(bitmap2, x, y, paint);   //x and y are bitmap's location
     }
}

按照萨德什库马尔的方式去做,即使不是更好,也可能是一样好的。谢谢你,Sadeshkumar。