Thats how I do it in my apps.

On May 5, 4:30 am, Mariano Kamp <mariano.k...@gmail.com> wrote:
> The onDraw() method starts from the scratch every time and so doesn't keep
> your drawings from the last invocation. Instead you would need to save all
> the previous points yourself and use them in onDraw().
>
> On Tue, May 5, 2009 at 9:25 AM, Sukitha Udugamasooriya 
> <suk...@gmail.com>wrote:
>
>
>
> > I want to draw strokes on my screen when the user touches. Next stroke
> > should be drawn from the end point
> > of the previous stroke.
> > This is my code. What happens here is just only the current stroke is
> > drawn. Previous strokes are vanished? What is wrong here? Please
> > help..
>
> > package src.test;
>
> > import android.app.Activity;
> > import android.content.Context;
> > import android.graphics.Bitmap;
> > import android.graphics.Canvas;
> > import android.graphics.Color;
> > import android.graphics.Paint;
> > import android.os.Bundle;
> > import android.view.MotionEvent;
> > import android.view.View;
> > import android.view.View.OnTouchListener;
>
> > public class ActDraw extends Activity implements OnTouchListener {
>
> >    float x = 200;
> >    float y = 200;
> >    float x1 = 10;
> >    float y1 = 45;
> >    float prvx = 150;
> >    float prvy = 150;
> >    MyView m;
>
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
>
> >        m = new MyView(this);
> >        m.setOnTouchListener(this);
> >        setContentView(m);
>
> >    }
> >    public boolean onTouch(View v, MotionEvent event) {
> >        switch (event.getAction()) {
> >        case MotionEvent.ACTION_DOWN: {
> >            prvx = x;
> >            prvy = y;
> >            x = event.getX();
> >            y = event.getY();
> >             m.invalidate();
> >        }
> >        }
> >        return false;
> >    }
>
> >    class MyView extends View {
> >        Paint p = new Paint();
> >        Bitmap bm;
> >        int i;
>
> >        public MyView(Context context) {
> >            super(context);
>
> >        }
>
> >       �...@override
> >        protected void onDraw(Canvas canvas) {
> >            super.onDraw(canvas);
> >            p.setColor(Color.GREEN);
> >            p.setStrokeWidth(4);
> >            canvas.drawLine(prvx, prvy, x, y, p);
> >         }
> >    }
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to