View inflate(int resource, ViewGroup root, boolean attachToRoot)
常用簡化形式:LayoutInflater.from(context).inflate(id, root) 等同 inflate(id, root, true)。
LayoutInflater.from(context):獲取系統佈局填充服務實例,用於將 XML 實例化為 View 對象。id:布局資源 ID(R.layout.xxx)。root(ViewGroup):
inflate(layoutId, parent, false),由 Adapter 管理添加,需父佈局參數計算尺寸。inflate(layoutId, null),獨立視圖無父容器。inflate(layoutId, container, true),直接掛載到容器。非 null root + false 是最通用安全的模式,獲取正確佈局參數且不破壞視圖層級結構。