在一个acitivity下添加一个view执行过程如下(通过xml加载):
10-25 08:56:04.891: D/myDebug(865): DrawView context set
10-25 08:56:04.980: D/myDebug(865): onFinishInflate
10-25 08:56:05.340: D/myDebug(865): onSizeChanged,w=216,h=353,oldw=0,oldh=0
10-25 08:56:05.400: D/myDebug(865): onLayout true
10-25 08:56:05.541: D/myDebug(865): onLayout false
10-25 08:56:18.391: D/myDebug(865): onDraw
注意:在xml中描述一个view,必须定义layout_width和layout_height
<org.crazyit.ui.DrawView
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</org.crazyit.ui.DrawView>
如果通过程序加载
10-25 09:00:08.631: D/myDebug(908): DrawView context
10-25 09:00:12.180: D/myDebug(908): from activity DrawView initialized
10-25 09:00:18.840: D/myDebug(908): from activity DrawView set width
10-25 09:00:22.400: D/myDebug(908): from activity DrawView set height
10-25 09:00:28.160: D/myDebug(908): from activity add view
10-25 09:00:35.680: D/myDebug(908): onSizeChanged,w=216,h=353,oldw=0,oldh=0
10-25 09:00:35.680: D/myDebug(908): onLayout true
10-25 09:00:35.830: D/myDebug(908): onLayout false
10-25 09:00:35.880: D/myDebug(908): onDraw
后来发现,添加viewgroup,viewgroup再添加view的时候。只有在actiivity oncreate 添加时,执行两遍