Create a custom View from scratch that draws a shape

This tests Android View measurement and drawing contracts. A strong answer covers: onMeasure resolves dimensions against parent MeasureSpec; onDraw renders with Canvas and Paint; constructors parse attributes.
This tests your understanding of the Android View rendering pipeline. A strong answer covers four steps: parse XML attributes in the constructor; override onMeasure to resolve dimensions against parent MeasureSpec modes; override onDraw to render with Canvas and Paint; and call invalidate to request redraw. Note that onMeasure must call setMeasuredDimension. A red flag is treating onMeasure as a simple size setter, allocating objects in onDraw, or confusing layout with draw.
Read the original → developer.android.com
- #android
- #custom-view
- #onmeasure
- #ondraw
- #view-lifecycle
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.