Android Canvas & Animation Interview Questions
Custom drawing, animation, and performance.
50 questions in this topic · 8 sample questions below
Practice Canvas & Animation in the quiz engine
Sample questions
Why is allocating a new Paint object inside a custom View's onDraw considered an anti-pattern?
Why: onDraw may be called on every frame, so allocations create garbage that triggers GC pauses and dropped frames; allocate Paint once as a field. Paint can absolutely be created elsewhere, which is exactly the recommended fix.
What is the key difference between invalidate() and postInvalidate() on a View?
Why: postInvalidate() posts the invalidation to the UI thread's message queue so it is safe from other threads, whereas invalidate() must be called on the UI thread. invalidate() is not synchronous; it just schedules a redraw for the next frame.
Calling invalidate() on a View schedules which pass(es)?
Why: invalidate() marks the view dirty and schedules only a redraw (draw pass). To re-trigger measure and layout you must call requestLayout(); a common misconception is that invalidate() lays out again.
In the Compose UI phases (composition, layout, drawing), animating a value that is only read inside a graphicsLayer block is efficient because it skips which phases?
Why: Reading state inside graphicsLayer's lambda defers the read to the draw phase, so changes skip composition and layout entirely. The misconception that graphicsLayer changes cause recomposition is exactly what this technique avoids.
What does the antiAlias flag on a Paint object control?
Why: Anti-aliasing smooths the pixelated edges of diagonal lines, curves, and text. It has nothing to do with hardware acceleration or reuse; transparency is controlled by alpha, not the anti-alias flag.
You call setLayerType(LAYER_TYPE_HARDWARE) on a View to speed up an alpha animation. What is the main trade-off?
Why: A hardware layer allocates an offscreen texture; it is fast for transforms and alpha but costs GPU memory and re-uploads whenever the layer's own content is invalidated. Hardware layers are not universally faster, which is why they should be applied only for the duration of an animation.
Which Paint.Style causes only the outline of a shape to be drawn using the Paint's stroke width?
Why: STROKE draws only the outline using strokeWidth. FILL_AND_STROKE draws both the interior and the outline, so it is not outline-only, and OUTLINE is not a valid Paint.Style constant.
To draw a bitmap source only inside a previously drawn circular region, which PorterDuff mode produces a circular crop?
Why: With the circle as destination and the bitmap as source, SRC_IN keeps the source only where the destination is opaque, yielding a circular crop. SRC_OVER simply draws the source on top without masking, so no clipping occurs.
Practice all 50 Canvas & Animation questions
These 8 are a sample. The full Canvas & Animation bank is scored, tracks your progress, and explains every answer.
More Android interview topics
- Android Hilt interview questions
- Android Coroutines & Flow interview questions
- Android Room interview questions
- Android Design Patterns interview questions
- Android Mobile System Design interview questions
- Android Coding Interview Patterns interview questions
- Android NDK interview questions
- Android Sensors interview questions
- Android Security interview questions
- Android Jetpack Compose interview questions
- Android CI/CD interview questions
- Android Git interview questions
- Android Unit Testing interview questions
- Android Kotlin interview questions
- Android Retrofit interview questions
- Android Architecture interview questions
- Android Android Framework interview questions
- Android Kotlin Multiplatform interview questions
- Android WorkManager & Background interview questions
- Android Performance & Memory interview questions