addView和addViewInLayout之间的区别是什么区别、addView、addViewInLayout

由网友(造梦怪咖丶o)分享简介:我已经看到了使用addView一些小部件,有时addViewInLayout。I have seen some widgets using addView and sometimes addViewInLayout.它们之间的区别是什么?会发生什么,如果我更换一个与其他的什么?What is the diffe...

我已经看到了使用addView一些小部件,有时addViewInLayout。

I have seen some widgets using addView and sometimes addViewInLayout.

它们之间的区别是什么? 会发生什么,如果我更换一个与其他的什么?

What is the difference between them? What will happen if I replace one with the other?

我应该布局过程中保持标志,并使用addViewInLayout或addView来呢?

Should I keep a flag during layout and use "addViewInLayout" or "addView" accordingly?

感谢。

BR, 亨利

PS。添加更多标签:removeview,removeviewinlayout

ps. add more tags: removeview, removeviewinlayout

推荐答案

它通常是一个坏主意,叫 addView onLayout ,因为 addView 内部触发 requestLayout 最终将调用 onLayout 。所以,你最终会触发一个布局,而你是在布局的中间。

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 是这样一个更安全的版本 addView 你真的要添加一个新的视图在 onLayout 。它基本上不会触发布局传递(不调用requestLayout内部)。

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).

请参阅该视频(由机器人工程师)的更多详细信息: http://www.youtube。 COM /手表?ν= HbAeTGoKG6k

See this video (by android engineer) for more detail: http://www.youtube.com/watch?v=HbAeTGoKG6k

阅读全文

相关推荐

最新文章