2. Charlie Tsai@Android Study Group
cha122977@gmail.com
Individual App Developer &
System Software Engineer@NVIDIA (will quit in Sep.)
Today’s source code
https://github.com/chatea/ViewDemo
3. Agenda
• View & ViewGroup
• Mechanism of View
• Live debugging
• Free topics :D
4. View
• Attached to window / Detached from window
• Measure
• Layout
• Draw
5. ViewGroup
• ViewGroup extend View (composition pattern)
• The draw functions are different:
• View.onDraw(Canvas);
• ViewGroup.dispatchDraw(Canvas);
6. Mechanism of View
• What does View do?
• What does View NOT do?
• Need to attach to Window
• measure: analysis the size of view
• layout: determine the position and size of view
• draw: real function to render the View
7. Mechanism of View
• Draw from parent, then to children
• Canvas is given by Android framework
• Cost of overlay?
8. Attach / Detach
• onAttachedToWindow() / onDetachedFromWindow()
• What is Window?
• WindowManager
• ViewRootImpl (composition pattern)
• interactive with WindowManager
• performTraversals() & scheduleTraversals()
• own the Surface and send Canvas to View
9. Measure
• How big this View should be?
• void onMeasure(int, int)
• setMeasuredDimension(int, int)