Wednesday, March 28, 2012

Drawing and erasing using touch on Android

Drawing/Erasing using touch is a common feature in many mobile phone/tablet based apps.
Writing code for this feature is pretty simple for android. Here are steps to do that:
  • add a custom view on which you will draw.
  • process touch event on view.
  • on touch event, record points where touch event occurred.
  • in onDraw method, draw points that were recorded.

Adding a custom view:

We will derive a class from View class for implementing drawing canvas.
And we will add this to UI tree. To add this to UITree, create a LinearLayout in which the
custom view will be added. The LinearLayout is declared in layout xml as:

...... read full blog post and get the code from here: http://blog.avabodh.com/2012/01/drawing-and-erasing-using-touch-on.html



 

No comments:

Post a Comment