Android canvas detect touch points

To detect the touch events on the canvas of a View class we can use the boolean method onTouchEvent(MotionEvent). In the View created in example below, it draws a line from previous touch point to new touch point. Add the View in activity_main.xml In MainActivity.java put following codes. Output

Create a View class using Canvas

In android we can use the canvas while creating a View by calling the onDraw(Canvas) method. Canvas is a class in android that allows us to perform 2D drawings on the View or Bitmap. Example 1 The code provided below is a simple example which uses Canvas to create a View containing a text, and … Read more