zoukankan      html  css  js  c++  java
  • inflate用一个XML源填充view. LayoutInflater


    java.lang.Object
        android.view.LayoutInflater
    This class is used to instantiate layout XML file into its corresponding View objects.
     It is never be used directly -- 
     use getLayoutInflater()  or getSystemService(String)  to retrieve a standard LayoutInflater instance 
     that is already hooked up to the current context and correctly configured for the device you are running on. 
     For example:

    LayoutInflater inflater = (LayoutInflater)context.getSystemService
          Context.LAYOUT_INFLATER_SERVICE);
    常用方法有:
    public View inflate (int resource, ViewGroup root)
    Since: API Level 1

    Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
    Parameters
    resource     ID for an XML layout resource to load (e.g., R.layout.main_page)
    root     Optional view to be the parent of the generated hierarchy.
    Returns

        * The root View of the inflated hierarchy. If root was supplied, this is the root View; otherwise it is the root of the inflated XML file. 
    注意:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View
    public View inflate (int resource, ViewGroup root, boolean attachToRoot)
    Since: API Level 1

    Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
    Parameters
    resource     ID for an XML layout resource to load (e.g., R.layout.main_page)
    root     Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)
    attachToRoot     Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.
    Returns

        * The root View of the inflated hierarchy. If root was supplied and attachToRoot is true, this is root; otherwise it is the root of the inflated XML file. 
    注意:如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。
    如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用,
    不会把新生成的View连接到root。当然返回的是新生成的View。

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    使用poi读取excel文件 Cannot get a text value from a numeric cell
    异步往数据库中插入每个用户的增删改操作日志
    mybatis where in语句中参数过多
    使用泛型实现对int数组或者String数组进行排序
    读取hdfs目录,并在web页面上展示文件里的内容
    java使用优先级队列实现哈夫曼编码
    使用JavaScript动态的绑定、解绑 a 标签的onclick事件,防止重复点击
    git概念和操作流程
    新的学习路径、学习想法和思路的头脑风暴:基于泰迪云课程,对数据分析和数据建模,机器学习算法进行统筹,接着是基于大数据的数据挖掘、进度、
    RSA加密算法流程,公钥加密,私钥解密
  • 原文地址:https://www.cnblogs.com/zsw-1993/p/4879870.html
Copyright © 2011-2022 走看看