As a result of executing the code, as you move your finger across the screen, Canva redraws the Bitmap with new coordinates. The inheritance from View.OnTouchListener was not and instead of onTouch was onTouchEvent. But I wanted the Ontouch listener to hang up on the ImageView. But as you can see, instead of the loath, I see setContentView (new GraphicsView (this)). So what is this new GraphicsView (this)? I understand that this is a GraphicsView object that inherits from View, but then what does it inherit from View? Why is it full screen and why is the background color black? where do these parameters come from? How do I hang an ImageView on it that I assign to an OnTouch listener?
public class MainActivity extends Activity { float touchX = 10,touchY= 10; private float korX = touchX, korY = touchY, initX=0, initY=0; ImageView ar; Bitmap bitmap; Canvas canvas; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new GraphicsView(this)); ar.setImageResource(R.drawable.areatouch); ar = (ImageView) this.findViewById(R.id.imageView); } public class GraphicsView extends View implements View.OnTouchListener{ public GraphicsView(Context context) { super(context); ar.setOnTouchListener(this); } @Override protected void onDraw(Canvas canvas) { Bitmap mybitmap = BitmapFactory.decodeResource(getResources(),R.drawable.face_box); canvas.drawBitmap(mybitmap, touchX, touchY, null); } public boolean onTouch(View v,MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: korX = touchX; korY = touchY; initX = event.getRawX(); initY = event.getRawY(); return true; case MotionEvent.ACTION_MOVE: touchX = korX + (event.getRawX() - initX); touchY = korY + (event.getRawY() - initY); invalidate(); return true; } return false; } } }