Hey, I'm new to android, and I just started fiddling with some simple example code I found online to get some practice. I found some code that has a red dot follow your finger, but I'd like to make the dot leave a trail like a paint brush. It looks like the program erases the previous paint area and puts down a new dot at your finger each frame; I made the 'V' in the upper left corner move to find that. Anyone have any clues?
import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.view.View.OnTouchListener; import android.view.ViewGroup.LayoutParams; public class MainActivity extends Activity implements OnTouchListener { private float x; private float y; private int moveX; Paint paint = new Paint(); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MyCustomPanel view = new MyCustomPanel(this); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); addContentView(view, params); view.setOnTouchListener(this); } private class MyCustomPanel extends View { public MyCustomPanel(Context context) { super(context); } @Override public void onDraw(Canvas canvas) { paint.setColor(Color.GREEN); paint.setStrokeWidth(6); canvas.drawLine(moveX,10,50,50,paint); paint.setColor(Color.RED); canvas.drawLine(50, 50, 90, 10, paint); canvas.drawCircle(50, 50, 3, paint); moveX++; canvas.drawCircle(x,y,3,paint); } } public boolean onTouch(View v, MotionEvent event) { x = event.getX(); y = event.getY(); v.invalidate(); return true; } }