首页 > 解决方案 > 使用 inflate with parent 和 attachToRoot true 或调用 addView() 将 childview 添加到 parent 有什么区别?

问题描述

我有一个 FrameLayout,我需要以编程方式膨胀子视图我试过这个layoutInflater.inflate(R.layout.child_layout, frameLayout,true)

我试过这个View childView = layoutInflater.inflate(R.layout.child_layout, frameLayout ,false) frameLayout.addView(childView)

还有这个View childView = layoutInflater.inflate(R.layout.child_layout,null) frameLayout.addView(childView)

它给出了相同的结果我想知道哪个正确使用?有什么区别 ?

标签: androidandroid-viewandroid-inflate

解决方案


推荐阅读