《Expert Android》关键点摘录之二

Drawing Phase: Mechanics of onDraw     

    The draw traversal is implemented in the View's draw() method. The protocol implemented by this method is:

	Draw the background
	Draw view's content by delegating to onDraw()
	Draw children by delegating to dispatchDraw()
	Draw decorations such as scroll bars

       As the trigger for the layout phase is requestLayout(), the trigger for the draw phase is invalidate(). When you invalidate a view, it goes up the chain and results in scheduling of the traversal from the view root. 

    Implementing Measure Pass

    In the measure pass, a custom view needs to return the size that it wants when it get painted in the subsequent draw pass. The view needs to set its dimentsions in the overriden onMeasure(). Setting the size of a view is not straightforward. Your view size depends on how your view is going to fit with the rest of the views. Android passes something called a mode bit to onMeasure() to give context to calculating the  size of the view.

   This mode bit can be one of three:AT_MOST, UNSPECIFIED, and EXACT.
 

上一篇:软件开发杂谈 001


下一篇:Understanding Android Custom Attributes: An Article