`
- 浏览:
1646149 次
-
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
相关推荐
LayoutInflater源码分析 inflate方法的区别
主要介绍了Android LayoutInflater分析的相关资料,需要的朋友可以参考下
Android 中LayoutInflater的使用
LayoutInflater Layout 与 Inflater[扩充]两个单词的合并,可以理解为:当前Activity 布局的扩充.
通过LayoutInflater.Factory实现主题切换功能,详见:http://blog.csdn.net/llew2011
Android 中LayoutInflater(布局加载器)之实战篇 博客的Demo 博客地址: http://blog.csdn.net/l540675759/article/details/78112989 两种方式实现小红书的引导页: (1)自定义View (2)自定义LayoutInflater....
NULL 博文链接:https://lxmgfd.iteye.com/blog/979716
LayoutInflater.from(context).inflate()方法的调研
android inflate demo,方便新手使用,下载导入android studio就可直接运行,简单明了的展现inflate不同参数的区别
在android中,LayoutInflater有点类似于Activity的findViewById(id),不同的是LayoutInflater是用来找layout下的xml布局文件,并且实例化!而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。...
NULL 博文链接:https://yufeng-zhu.iteye.com/blog/1676207
android中LayoutInflater的使用.pdf
JavaScript应用实例-LayoutInflater.js
Android LayoutInflater加载布局详解 对于有一定Android开发经验的同学来说,一定使用过LayoutInflater.inflater()来加载布局文件,但并不一定去深究过它的原理,比如 1.LayoutInflater为什么可以加载layout文件? ...
down-test-Android 获得 LayoutInflater 实例的三种方式
在平时的开发过程中,我们经常会用LayoutInflater这个类,比如说在Fragment$onCreateView和RecyclerView.Adapter$onCreateViewHolder中都会用到。它的用法也无非就是LayoutInflater.inflate(resourceId, root, ...
这是老外写的经典Android代码,对学习AsyncTask、JSONAdapter、LayoutInflater很有用