java.lang.Object
android.view.LayoutInflater
ThisclassisusedtoinstantiatelayoutXMLfileintoitscorrespondingViewobjects.
Itisneverbeuseddirectly--
usegetLayoutInflater()orgetSystemService(String)toretrieveastandardLayoutInflaterinstance
thatisalreadyhookeduptothecurrentcontextandcorrectlyconfiguredforthedeviceyouarerunningon.
Forexample:
LayoutInflaterinflater=(LayoutInflater)context.getSystemService
Context.LAYOUT_INFLATER_SERVICE);
常用方法有:
publicViewinflate(intresource,ViewGrouproot)
Since:APILevel1
Inflateanewviewhierarchyfromthespecifiedxmlresource.ThrowsInflateExceptionifthereisanerror.
Parameters
resourceIDforanXMLlayoutresourcetoload(e.g.,R.layout.main_page)
rootOptionalviewtobetheparentofthegeneratedhierarchy.
Returns
*TherootViewoftheinflatedhierarchy.Ifrootwassupplied,thisistherootView;otherwiseitistherootoftheinflatedXMLfile.
注意:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View
publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot) Since:APILevel1 Inflateanewviewhierarchyfromthespecifiedxmlresource.ThrowsInflateExceptionifthereisanerror. Parameters resourceIDforanXMLlayoutresourcetoload(e.g.,R.layout.main_page) rootOptionalviewtobetheparentofthegeneratedhierarchy(ifattachToRootistrue),orelsesimplyanobjectthatprovidesasetofLayoutParamsvaluesforrootofthereturnedhierarchy(ifattachToRootisfalse.) attachToRootWhethertheinflatedhierarchyshouldbeattachedtotherootparameter?Iffalse,rootisonlyusedtocreatethecorrectsubclassofLayoutParamsfortherootviewintheXML. Returns *TherootViewoftheinflatedhierarchy.IfrootwassuppliedandattachToRootistrue,thisisroot;otherwiseitistherootoftheinflatedXMLfile. 注意:如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。 如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用, 不会把新生成的View连接到root。当然返回的是新生成的View。
android.view.LayoutInflater
ThisclassisusedtoinstantiatelayoutXMLfileintoitscorrespondingViewobjects.
Itisneverbeuseddirectly--
usegetLayoutInflater()orgetSystemService(String)toretrieveastandardLayoutInflaterinstance
thatisalreadyhookeduptothecurrentcontextandcorrectlyconfiguredforthedeviceyouarerunningon.
Forexample:
LayoutInflaterinflater=(LayoutInflater)context.getSystemService
Context.LAYOUT_INFLATER_SERVICE);
常用方法有:
publicViewinflate(intresource,ViewGrouproot)
Since:APILevel1
Inflateanewviewhierarchyfromthespecifiedxmlresource.ThrowsInflateExceptionifthereisanerror.
Parameters
resourceIDforanXMLlayoutresourcetoload(e.g.,R.layout.main_page)
rootOptionalviewtobetheparentofthegeneratedhierarchy.
Returns
*TherootViewoftheinflatedhierarchy.Ifrootwassupplied,thisistherootView;otherwiseitistherootoftheinflatedXMLfile.
注意:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View
publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot) Since:APILevel1 Inflateanewviewhierarchyfromthespecifiedxmlresource.ThrowsInflateExceptionifthereisanerror. Parameters resourceIDforanXMLlayoutresourcetoload(e.g.,R.layout.main_page) rootOptionalviewtobetheparentofthegeneratedhierarchy(ifattachToRootistrue),orelsesimplyanobjectthatprovidesasetofLayoutParamsvaluesforrootofthereturnedhierarchy(ifattachToRootisfalse.) attachToRootWhethertheinflatedhierarchyshouldbeattachedtotherootparameter?Iffalse,rootisonlyusedtocreatethecorrectsubclassofLayoutParamsfortherootviewintheXML. Returns *TherootViewoftheinflatedhierarchy.IfrootwassuppliedandattachToRootistrue,thisisroot;otherwiseitistherootoftheinflatedXMLfile. 注意:如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。 如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用, 不会把新生成的View连接到root。当然返回的是新生成的View。