LayoutInflate.inflate(int resourceId, ViewGroup root, boolean attachToRoot)三個參數含義:佈局
首先明白下面知識點:spa
給控件所指定的layout_width和layout_height究竟是什麼意思?該屬性的表示一個控件在容器中的大小,就是說這個控件必須在容器中,這個屬性纔有意義,不然無心義。容器
當:root == null,不管attachToRoot 是否ture仍是falselayout
ResourceId的根節點沒有依賴的父佈局(容器),因此width和height屬性失效view
當:root != null,若是attachToRoot = ture;vi
則將resourceId對應得佈局加載到root中,並將root返回;resourceId中的width和height屬性有效co
當:root != null,若是attachToRoot = false;參數
則將resourceId對應的view設置容器爲root,可是不添加到root中,resourceId中的width和height屬性有效控件