zoukankan      html  css  js  c++  java
  • inflate(int resource, ViewGroup root, boolean attachToRoot)见解

    /**
    * Inflate a new view hierarchy from the specified xml resource. Throws
    * {@link InflateException} if there is an error.
    *
    * @param resource ID for an XML layout resource to load (e.g.,
    * <code>R.layout.main_page</code>)
    * @param root Optional view to be the parent of the generated hierarchy (if
    * <em>attachToRoot</em> is true), or else simply an object that
    * provides a set of LayoutParams values for root of the returned
    * hierarchy (if <em>attachToRoot</em> is false.)
    * @param 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.
    * @return 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.
    */

    inflate(int resource, ViewGroup root, boolean attachToRoot)

    view=inflater.inflate(R.layout.fragment1, null,false)的三个参数详解;

    第一个参数:加载view的布局文件。

    第二个参数:

    1.参数为空的情况,xml里的根布局(也就是最外层布局),将不会被加载(xml文件的根布局会失效);

    2.不为空的情况,

    系统会调用params = root.generateLayoutParams(attrs);//根据xml文件的宽,高 获取params

     temp.setLayoutParams(params); 会把这个布局加载进去;也就是说xml文件的根布局不会失效;

    第三个参数:

    如果为true:

    系统会调用:root.addView(temp, params); 会自动调用addview();

    https://blog.csdn.net/dongpeng0314/article/details/51737899

  • 相关阅读:
    虚拟机磁盘和OSNetworkManagement
    虚拟化的设计考量
    魔獸世界台服身份證ID生成器
    完美的Windows Server 2008 R2 SP1 模板
    Windows 脚本主机概述
    创建动态链接库的方法简介
    iPad3越狱方法
    关于用netsh.exe配置系统防火及网络
    金蝶客户端多用户远程桌面解决方案
    poj 1459 最大流(EK实现)
  • 原文地址:https://www.cnblogs.com/feng9exe/p/9284130.html
Copyright © 2011-2022 走看看