0
0
Android Kotlinmobile~5 mins

Custom drawing (Canvas) in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AonCreate()
BonDraw(canvas: Canvas)
ConStart()
DonMeasure()
What does the Paint object control when drawing on a canvas?
AThe style and color of what is drawn
BThe size of the canvas
CThe layout of the view
DThe touch events
Why is it important to avoid creating new objects inside onDraw?
AIt slows down drawing performance
BIt causes the app to crash
CIt changes the canvas size
DIt disables touch events
How do you request a view to redraw itself?
Acall <code>refresh()</code>
Bcall <code>draw()</code>
Ccall <code>start()</code>
Dcall <code>invalidate()</code>
Which of these can you draw on a Canvas?
AShapes like circles and rectangles
BText
CAll of the above
DImages (bitmaps)
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.