我在這種情況下,我想繪製線條與一段時間的一段時間。我試圖通過使用thread.but而不是它爲我工作。 目標是我有5行。線應該繪製一個接一個,延遲5秒。在onDraw()方法中使用Thread.sleep(5000),但所有線在5秒後繪製,這些線沒有周期性繪製...我怎樣才能定期繪製線...繪製直線的線條
代碼段::
public class PaintDemoActivity extends Activity {
DragView drawView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
drawView = new DragView(this);
setContentView(drawView);
drawView.requestFocus();
}
}
DragView類::
public class DragView extends View implements OnTouchListener {
Paint paint = new Paint();
public DragView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
//paint.setStyle(Style.STROKE);
paint.setAntiAlias(true);
}
@Override
public void onDraw(final Canvas mCanvas) {
canvas.drawCircle(p.x, p.y, 5, paint);
canvas.drawLine(60, 60, 120,60, paint);
canvas.drawLine(60, 60, 60, 120, paint);
canvas.drawLine(60, 120, 120, 120, paint);
canvas.drawLine(120, 120, 120, 180, paint);
canvas.drawLine(120, 180, 60, 180, paint);
}
}
感謝。
謝謝噸......它的工作.... – Taruni
尼斯一個不錯的。 –