Reputation: 221
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?
Upvotes: 2
Views: 3156
Reputation: 93678
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.
Upvotes: 0
Reputation: 234847
Comparing View
and Canvas
is comparing apples and oranges. Anything that goes onto the screen is in a View
. A Canvas
just provides a way to draw things; it's used internally by all View
types, including ImageView
. If you implement a custom View
type, a Canvas
is the argument to onDraw()
with which you can do your custom drawing. A Canvas
can also be used to draw into an off-screen Bitmap
object, but you still need to use some sort of View
object to get it to the screen. If you're familiar with Java's AWT or Swing, think of Android's Canvas
class as similar to J2SE's Graphics
class.
For more information about how all this works, check out the Android developer guide topic Canvas and Drawables.
Upvotes: 4