inflate用一个XML源填充view. LayoutInflater

前端之家收集整理的这篇文章主要介绍了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。
原文链接:https://www.f2er.com/xml/300005.html

猜你在找的XML相关文章