加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

inflate用一个XML源填充view. LayoutInflater

发布时间:2020-12-15 23:31:39 所属栏目:百科 来源:网络整理
导读:java.lang.Object android.view.LayoutInflater ThisclassisusedtoinstantiatelayoutXMLfileintoitscorrespondingViewobjects. Itisneverbeuseddirectly-- usegetLayoutInflater()orgetSystemService(String)toretrieveastandardLayoutInflaterinstance that


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。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读