计时器,复习

时间:2010-11-25 11:14:43

标签: java android timer

我如何开发一个应用程序,在固定坐标的屏幕上绘制一条线,设置一个1秒的重复计时器?在计时器的每个刻度线上,线条都会刷新。

LineRefresh.java:

package LineRefresh.xyz.com;

import java.util.Timer;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;

public class LineRefresh extends Activity {
DrawView drawView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
}

DrawView.java:

 package LineRefresh.xyz.com;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
 import android.view.View;

public class DrawView extends View {
Paint paint = new Paint();

public DrawView(Context context) {
super(context);

}

@Override
public void onDraw(Canvas canvas) {
paint.setColor(Color.BLACK);
canvas.drawLine(50, 200, 270, 200, paint);
}  

}

1 个答案:

答案 0 :(得分:0)

使用Handler并使用postDelayed()来安排绘制一条线。

绘制线后,还安排另一个postDelayed()继续此过程。