inflate用一个XML源填充view. LayoutInflater


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。

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念