Are the ImageView class and Canvas class completely different ways to draw things or are they related? Also, what are the pros and cons to using each of them?
ImageView vs Canvas
3.1k views Asked by Sygnerical At
2
There are 2 answers
3
On
AN ImageView is a view that holds a bitmap object. You do not draw to it at all. It's just a bitmap on screen.
A canvas is a low level drawing abstraction- its a place you can draw to. You can do any type of drawing there- lines, images text, etc. Its what you use if you want to draw a complex view from scratch, or draw to make an in memory bitmap.
Comparing
ViewandCanvasis comparing apples and oranges. Anything that goes onto the screen is in aView. ACanvasjust provides a way to draw things; it's used internally by allViewtypes, includingImageView. If you implement a customViewtype, aCanvasis the argument toonDraw()with which you can do your custom drawing. ACanvascan also be used to draw into an off-screenBitmapobject, but you still need to use some sort ofViewobject to get it to the screen. If you're familiar with Java's AWT or Swing, think of Android'sCanvasclass as similar to J2SE'sGraphicsclass.For more information about how all this works, check out the Android developer guide topic Canvas and Drawables.