`
kanwoerzi
  • 浏览: 1646149 次
文章分类
社区版块
存档分类
最新评论

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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics