我正在更新一个线程中的函数,以使一行符合android中的循环路径:
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
renderEnvironmentalVariables(canvas);
}
private void renderEnvironmentalVariables(Canvas canvas){
while(angle > 360){
angle -= 360;
}
canvas.drawColor(0xFFe6e6e6);
//renderBaseRadar(canvas);
float origin = width / 2;
float x = origin + (float) Math.cos(angle) * (origin);
float y = origin + (float) Math.sin(angle) * (origin);
Log.i("Radio frequency tracker", y + "_" + x);
Paint lineColor = new Paint();
lineColor.setColor(0xFFFFFFFF);
lineColor.setStyle(Paint.Style.STROKE);
lineColor.setStrokeWidth(5);
canvas.drawLine(origin, origin, x, y, lineColor);
angle += 20;
}
onDraw(canvas);
//Log.i("Radio frequency tracker", "Updating canvas thread");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
相反,如果在原点周围转得相当平滑,那么该线就会停留在一个地方并且不会移动,即使Log功能记录了新的坐标......
我做错了什么,如何解决?
答案 0 :(得分:1)
你不应该直接调用onDraw。请改为调用postInvalidate。