欧尔。我正面临着androird surfaceView的问题。我试图通过改变它的x,y坐标来设置球的动画。但球正在消失......请查看代码并确定问题, regards.`
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawBitmap(tile1, axisX, axisY,null); //LINE ONE objects
canvas.drawBitmap(tile2, axisX+78, axisY,null);
canvas.drawBitmap(tile3, axisX+156, axisY,null);
canvas.drawBitmap(tile4, axisX+234, axisY,null);
canvas.drawBitmap(movingStick, (mWidth-movingStick.getWidth())/2, mHeight-200,null);
canvas.drawBitmap(mBall, balCurrPosX,balCurrPosY ,null);
}
//线程代码
Thread t=new Thread(new Runnable() {
private boolean moveUp = true;
@Override
public void run() {
// TODO Auto-generated method stub
try{
while (true) {
if (balCurrPosY >= mHeight){
moveUp= false;
}else if(balCurrPosX<=0){
moveUp = true;
}
if(moveUp)
balCurrPosY--;
else
balCurrPosY++;
Thread.sleep(2000);
postInvalidate();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});`
答案 0 :(得分:0)
您忘记在代码末尾开始新的主题:
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();