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
3k 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
View
andCanvas
is comparing apples and oranges. Anything that goes onto the screen is in aView
. ACanvas
just provides a way to draw things; it's used internally by allView
types, includingImageView
. If you implement a customView
type, aCanvas
is the argument toonDraw()
with which you can do your custom drawing. ACanvas
can also be used to draw into an off-screenBitmap
object, but you still need to use some sort ofView
object to get it to the screen. If you're familiar with Java's AWT or Swing, think of Android'sCanvas
class as similar to J2SE'sGraphics
class.For more information about how all this works, check out the Android developer guide topic Canvas and Drawables.