LayoutInflater

java.lang.Object
android.view.LayoutInflater
ThisclassisusedtoinstantiatelayoutXMLfileintoitscorrespondingViewobjects.
Itisneverbeuseddirectly--
usegetLayoutInflater()orgetSystemService(String)toretrieveastandardLayoutInflaterinstance
thatisalreadyhookeduptothecurrentcontextandcorrectlyconfiguredforthedeviceyouarerunningon.

Forexample:
LayoutInflaterinflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
常用方法有:
<wbr style="line-height:25px">publicViewinflate(intresource,ViewGrouproot)</wbr><wbr style="line-height:25px"><br style="line-height:25px"> Since:APILevel1<br style="line-height:25px"> Inflateanewviewhierarchyfromthespecifiedxmlresource.ThrowsInflateExceptionifthereisanerror.<br style="line-height:25px"><span style="line-height:25px">参数</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">resource</span>IDforanXMLlayoutresourcetoload(e.g.,R.layout.main_page)<br style="line-height:25px"><span style="color:#993300; line-height:25px">root</span>Optionalviewtobetheparentofthegeneratedhierarchy. <div style="line-height:25px"> <span style="line-height:25px">返回</span><br style="line-height:25px"> *TherootViewoftheinflatedhierarchy.Ifrootwassupplied,thisistherootView;otherwiseitistherootoftheinflatedXMLfile.<br style="line-height:25px"><span style="line-height:25px">注意</span>:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot)</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> Since:APILevel1<br style="line-height:25px"><span style="color:#003366; line-height:25px">Inflateanewviewhierarchyfromthespecifiedxmlresource.ThrowsInflateExceptionifthereisanerror.</span><br style="line-height:25px"><span style="line-height:25px">参数</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">resource</span>IDforanXMLlayoutresourcetoload(e.g.,R.layout.main_page)<br style="line-height:25px"><span style="color:#993300; line-height:25px">root</span>Optionalviewtobetheparentofthegeneratedhierarchy(ifattachToRootistrue),orelsesimplyanobjectthatprovidesasetofLayoutParamsvaluesforrootofthereturnedhierarchy(ifattachToRootisfalse.)<br style="line-height:25px"><span style="color:#993300; line-height:25px">attachToRoot</span>Whethertheinflatedhierarchyshouldbeattachedtotherootparameter?Iffalse,rootisonlyusedtocreatethecorrectsubclassofLayoutParamsfortherootviewintheXML.<br style="line-height:25px"><span style="line-height:25px">返回</span><br style="line-height:25px"> *TherootViewoftheinflatedhierarchy.IfrootwassuppliedandattachToRootistrue,thisisroot;otherwiseitistherootoftheinflatedXMLfile.<br style="line-height:25px"><span style="line-height:25px">注意</span>:如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。<br style="line-height:25px"> 如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用,<br style="line-height:25px"> 不会把新生成的View连接到root。当然返回的是新生成的View。</wbr> </div> </wbr>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值