码迷,mamicode.com
首页 > 其他好文 > 详细

inflate 参数 的解释

时间:2019-07-01 13:46:50      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:eset   equals   set   result   get   nal   layout   设计   float   

root,和attachToRoot 2个参数有4种组合,但是有一组合无意义。
感觉这个函数写的太废了。非常明显 boolean attachToRoot,这个参数 放在前面,root在后面更好理解一点。
是否要附加根节点上,之后在看跟节点是否为空。难道是英文的语法导致??i go first!
attachToRoot
root  
true null 无意义
true not null xml 再套一个viewgroup。  这样最后,应该就2个相同的viewgroup了吧。  用在特殊情况下
false null 直接返回xml。  这种情况下  xml内的根点的宽高属性,就会变成默认的warp_context值。一般不用
false not null 只需要xml 的外层的父group布局类型,一般使用这种。设计的时候一般是这种思路,xml和外层是同一个布局类型。这样好衔接










干脆自己封下。省的去记毫无用处的知识点。这些设置类的知识点。变化太大。记住没有任何用作。
//activity helper
    public static class LS_Activity
    {
        
        public static View inflast_Normal(Context context,int rid,ViewGroup viewGroup)
        {
            return LayoutInflater.from(context).inflate(rid, viewGroup,false);
        }

        public static View inflast_WrapFather(Context context,int rid,ViewGroup viewGroup)
        {
            return LayoutInflater.from(context).inflate(rid, viewGroup,true);
        }

        public static View inflast_ClearArrer(Context context,int rid)
        {
            return LayoutInflater.from(context).inflate(rid, null,false);
        }
    }

 




源代码减缩。
public View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot) 
       {
            final Context inflaterContext = mContext;
            Context lastContext = (Context) mConstructorArgs[0];
            mConstructorArgs[0] = inflaterContext;
            
            final AttributeSet attrs = Xml.asAttributeSet(parser);
            View result = root;

            int type=getXmlPullParser.START_TAG;// Look for the root node.
            final String name = parser.getName();
            if (TAG_MERGE.equals(name) && root != null && attachToRoot==true) //如果xml的根节点是merge.
            {
                rInflate(parser, root, inflaterContext, attrs, false);
            } 
            else 
            {
                final View temp = createViewFromTag(root, name, inflaterContext, attrs);
                ViewGroup.LayoutParams params = null;

                if (root != null && attachToRoot==false)//用xml的作为根节点,并且附加参数。
                {
                    params = root.generateLayoutParams(attrs);
                    temp.setLayoutParams(params);
                    rInflateChildren(parser, temp, attrs, true);
                }
                else if(root != null && attachToRoot==true)//用xml上层作为根节点,并且使用上层的布局类型。
                {
                    root.addView(temp, params);
                }
                else if(root == null || attachToRoot==false)//用xml的作为根节点
                {
                    result = temp;
                }
            }

            
            return result;
    }

 

inflate 参数 的解释

标签:eset   equals   set   result   get   nal   layout   设计   float   

原文地址:https://www.cnblogs.com/lsfv/p/11113411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!