当前位置: 首页 > wzjs >正文

三合一网站建设百度入口网址

三合一网站建设,百度入口网址,湖北seo,枣庄高端网站定制前言 对于LayoutInflater.from(this).inflate()方法的几个参数以及用法总是迷迷糊糊,源码看了忘,忘了看,因此决定写这篇博客做下记录。 源码解析 我们知道,调用LayoutInflater.from(this).inflate()方法最终都会走三参的方法 p…

前言

对于LayoutInflater.from(this).inflate()方法的几个参数以及用法总是迷迷糊糊,源码看了忘,忘了看,因此决定写这篇博客做下记录。

源码解析

我们知道,调用LayoutInflater.from(this).inflate()方法最终都会走三参的方法
public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)
,这里先简单说明下三个参数:

resource:表示需要加载资源的id;

root:表示resource资源需要被添加的根布局;

attachToRoot:表示resource是否需要被绑定到root上;

接下来我们重点分析下相关源码

inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)

    public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) {final Resources res = getContext().getResources();...View view = tryInflatePrecompiled(resource, res, root, attachToRoot);if (view != null) {return view;}XmlResourceParser parser = res.getLayout(resource);try {return inflate(parser, root, attachToRoot);//重点看这个代码} finally {parser.close();}}

inflate(parser, root, attachToRoot)

  public View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot) {synchronized (mConstructorArgs) {...View result = root; //result默认赋值为roottry {...if (TAG_MERGE.equals(name)) {.... //merge标签 这里不关注} else {// 将temp赋值为xml资源的根布局viewfinal View temp = createViewFromTag(root, name, inflaterContext, attrs);ViewGroup.LayoutParams params = null;if (root != null) {//如果传入的root参数不为空,则创建root对应的LayoutParamsparams = root.generateLayoutParams(attrs);if (!attachToRoot) {//如果传入的attachToRoot为false,则给temp布局设置LayoutParamstemp.setLayoutParams(params);}}// 绑定childrenrInflateChildren(parser, temp, attrs, true);...if (root != null && attachToRoot) {//如果root不为null并且attachToRoot为true时,将temp添加到root中,并设置对应的LayoutParamsroot.addView(temp, params);}if (root == null || !attachToRoot) {// root为null 或者 attachToRoot为false时,result = tempresult = temp;}}} catch (XmlPullParserException e) {final InflateException ie = new InflateException(e.getMessage(), e);ie.setStackTrace(EMPTY_STACK_TRACE);throw ie;} catch (Exception e) {final InflateException ie = new InflateException(getParserStateDescription(inflaterContext, attrs)+ ": " + e.getMessage(), e);ie.setStackTrace(EMPTY_STACK_TRACE);throw ie;} finally {// Don't retain static reference on context.mConstructorArgs[0] = lastContext;mConstructorArgs[1] = null;Trace.traceEnd(Trace.TRACE_TAG_VIEW);}return result; //返回结果}}

总结

  • 调用LayoutInflater.from(this).inflate(resource,null)不会将resource添加到布局中,结果返回resource资源根布局view,但不会设置对应的父布局LayoutParams属性【resource布局文件最外层的layout_width和layout_height等跟父布局有关的位置属性都会失效】;

  • 调用LayoutInflater.from(this).inflate(resource,root)会将resource添加到root布局中,同时会设置对应的父布局LayoutParams属性,结果返回root本身;

  • 调用LayoutInflater.from(this).inflate(resource,root,true)LayoutInflater.from(this).inflate(resource,root)方法效果一致,结果返回root本身;

  • 调用LayoutInflater.from(this).inflate(resource,root,false)不会将resource添加到root中,结果返回resource资源根布局view,同时会设置对应的父布局LayoutParams属性

  • 下面代码效果相同;

LayoutInflater.from(this).inflate(resource,root)
等同于
LayoutInflater.from(this).inflate(resource,root,true)
等同于
View resourceView = LayoutInflater.from(this).inflate(resource,root,false)
root.addView(resourceView)

结语

如果以上文章对您有一点点帮助,希望您不要吝啬的点个赞加个关注,您每一次小小的举动都是我坚持写作的不懈动力!ღ( ´・ᴗ・` )

http://www.dtcms.com/wzjs/405179.html

相关文章:

  • 侦探公司做网站的资料百度题库
  • 兰州建设厅网站seo公司 杭州
  • 数据库与网站建设的关系百度投诉电话
  • 网站开发后端做那些品牌推广案例
  • 有没有做兼职的网站百度推广平台登录入口
  • 做淘宝券网站网络营销案例ppt
  • 潞城建设局网站怎么把抖音关键词做上去
  • 开通网站软件的会计科目怎么做项目优化seo
  • 怎样给公司做推广 网站线上销售平台都有哪些
  • 网站图片大小优化怎么做一个公司网站
  • 网站建设公司 佛山自己建网站
  • 重庆网站建设建站收费优秀企业网站欣赏
  • 做网站号码怎么样才能引流客人进店
  • 深圳做网站 信科网络新区seo整站优化公司
  • 做网站生意越来越差百度关键词推广一年多少钱
  • 网站设计项目明细曹操博客seo
  • 织梦网站地图怎么做xml自己制作网页的网站
  • 橙色营销网站交换友链平台
  • discuz轻社区模板东莞seo建站咨询
  • 电子商务网站建设项目无锡seo培训
  • 网站如何做图片自动切换google下载app
  • 动漫视频网站模板b2b模式的电商平台有哪些
  • 做网站是要编程吗百度我的订单查询
  • 营销型网站建设一般要多少钱最近的电脑培训班在哪里
  • 电子政务网站模版百度手机助手app官方下载
  • 转业做网站的工具b2b电子商务网站
  • 网站个人主页云搜索app官网
  • 做文创的网站站长工具域名查询ip
  • 网站里弹窗怎么做培训学校资质办理条件
  • 在视频网站中做节目怎么挣钱企业网站的网络营销功能