i am in situation where i want to draw lines one by one with some time period. I tried to do it by using thread.but it didnt work for me. The objective is i've 5 lines. the lines should be drawn one after one with 5seconds delay .Using Thread.sleep(5000) in onDraw() method but all the lines were drawn after 5seconds those were not drawn periodically...how can i draw lines periodically...
code snippet::
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 Class ::
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);
}
}
Thanks.
seems u need to use the runnable and in the runnable u have to invalidate the canvas view , ypur code seems like that .
Ammu
try this code
where mCanvas is your canvas, v is your View, touchpaint is your Paint & Main.this is your activity
Another way, a bit more generic: