Recall & Review
beginner
What is the purpose of the <code>Canvas</code> class in Android custom drawing?The <code>Canvas</code> class provides the drawing surface on which you can draw shapes, text, and images in custom views.Click to reveal answer
beginner
Which method do you override to perform custom drawing in an Android View?
You override the
onDraw(canvas: Canvas) method to perform custom drawing on the view's canvas.Click to reveal answer
beginner
What is the role of the
Paint object when drawing on a Canvas?The
Paint object defines the style and color used for drawing shapes, text, and bitmaps on the canvas.Click to reveal answer
intermediate
Why should you avoid creating new objects inside the
onDraw method?Creating new objects inside
onDraw can cause performance issues because this method is called frequently during rendering.Click to reveal answer
beginner
How can you trigger a redraw of a custom view in Android?
Call the
invalidate() method on the view to request a redraw, which will call onDraw again.Click to reveal answer
Which method provides the canvas to draw on in a custom Android view?
✗ Incorrect
The
onDraw(canvas: Canvas) method is where you receive the canvas to perform custom drawing.What does the
Paint object control when drawing on a canvas?✗ Incorrect
Paint defines color, style, stroke width, and other drawing attributes.Why is it important to avoid creating new objects inside
onDraw?✗ Incorrect
Creating objects in
onDraw can slow down rendering because it is called many times.How do you request a view to redraw itself?
✗ Incorrect
Calling
invalidate() tells the system to redraw the view by calling onDraw.Which of these can you draw on a Canvas?
✗ Incorrect
Canvas supports drawing shapes, text, and images.
Explain how to create a simple custom view that draws a red circle using Canvas and Paint.
Think about what you do inside onDraw and how Paint affects drawing.
You got /3 concepts.
Describe why performance matters in custom drawing and how to optimize your onDraw method.
Consider how often onDraw is called and what slows it down.
You got /3 concepts.