Its generally a bad idea to call addView
inside onLayout
because addView
internally triggers a requestLayout
which eventually will call onLayout
. So you end up triggering a layout while you are in the middle of a layout.
addViewInLayout
is a "safer" version of the addView
in the case you really have to add a new view in onLayout
. It basically doesn't trigger a layout pass (doesn't call requestLayout internally).
See this video (by android engineer) for more detail: http://www.youtube.com/watch?v=HbAeTGoKG6k