Cracking Android SDE2/SDE3 Interviews in 2026: Deep Dives, Code, Follow-ups | Part-5
51. Custom View onMeasure? When you implement a custom View , you’re participating in Android’s three-phase rendering pipeline : Measure phase → onMeasure Layout phase → onLayout Draw phase → onDraw Each phase has a strict responsibility . Mixing them is a common junior mistake. 1️⃣ onMeasure() — How big do you want to be? Purpose onMeasure() decides how much space the View needs , based on: Parent constraints ( MeasureSpec ) Your content Padding Desired intrinsic size It does NOT position anything and must not draw . Understanding MeasureSpec Each dimension comes as an Int encoding: Mode Size Modes Correct Mental Model Think of onMeasure() as a negotiation : Here’s what I want” vs “Here’s what the parent allows Android provides helpers to avoid mistakes. Best Practice Implementation Pattern override fun onMeasure (widthMeasureSpec: Int , heightMeasureSpec: Int ) { val desiredSize = paddingLeft + contentSize + paddingRight ...