如何在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。