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

西安网站建设哪家好推广网站怎么制作

西安网站建设哪家好,推广网站怎么制作,惠州市建设局网站办事指南,系统构建前言 对于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/357253.html

相关文章:

  • 郴州市北湖区泉州seo技术
  • 政府网站制作平台石家庄网站建设方案
  • 咋做抽奖网站青岛seo精灵
  • 那个网站可以免费做风面邯郸网站seo
  • 湖南电商平台网站建设百度排名软件
  • 丽水品牌网站设计上海官网seo
  • 网站建设依据什么法律深圳网站制作哪家好
  • 天津协会网站建设世界军事新闻
  • 公司网站改版方案盛世品牌推广策略有哪几种
  • 品牌网站建设公司有哪些优秀的网页设计案例
  • 国家骨干高职院校建设网站自己怎么开网站
  • 青海专业网站建设推广平台建设广东做seo的公司
  • 维护网站是什么工作电商平台链接怎么弄
  • 做网站的的价位推广方式和推广渠道
  • 城市中国商业管理后台seo全国最好的公司
  • 新网站建设平台合肥网络seo
  • 湖北建设厅网站首页宁德seo推广
  • 网站购物车功能小程序开发流程
  • 建立网站的工具最新国内新闻10条
  • java私人网站西安seo全网营销
  • 福建祥盛建设有限公司网站百度广告投诉电话客服24小时
  • 企业响应式网站建设报价云南seo简单整站优化
  • 企业信息化建设方案 网站seo推广一个月见效
  • 室外设计网站推荐深圳网站关键词排名优化
  • 手机网站模板演示河北百度竞价优化
  • 国外免费b2b平台有哪些网站更换服务器对seo的影响
  • 用c语言做公司网站有链接的网站
  • 简述网站建设的步骤网络营销的主要推广方式
  • 武汉网站建设推广服务百度账号中心
  • 建设和管理环保网站市场营销案例150例