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

站规划在网站建设中的作用哪家网站做的比较好

站规划在网站建设中的作用,哪家网站做的比较好,西部数码网站管理助手破解版,网站打开速度多少时间安卓绘制原理概览_油炸板蓝根的博客-CSDN博客 搜了一下,全网居然没有人提过 measureCache。 在前文中提到过,measure的时候,如果命中了 measureCache,会跳过 onMeasure,同时会设置 PFLAG3_MEASURE_NEEDED_BEFORE_LAYOU…

安卓绘制原理概览_油炸板蓝根的博客-CSDN博客

        搜了一下,全网居然没有人提过 measureCache。

        在前文中提到过,measure的时候,如果命中了 measureCache,会跳过 onMeasure,同时会设置 PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT标志位,其作用顾名思义,需要在 layout 前进行 measure。

public class View {public final void measure(int widthMeasureSpec, int heightMeasureSpec) {if (mMeasureCache == null) mMeasureCache = new LongSparseLongArray(2);......int cacheIndex = forceLayout? -1: mMeasureCache.indexOfKey(key);if (cacheIndex < 0 || sIgnoreMeasureCache) {// measure ourselves, this should set the measured dimension flag backonMeasure(widthMeasureSpec, heightMeasureSpec);mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;} else {long value = mMeasureCache.valueAt(cacheIndex);// Casting a long to int drops the high 32 bits, no mask neededsetMeasuredDimensionRaw((int) (value >> 32), (int) value);mPrivateFlags3 |= PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;}}public void layout(int l, int t, int r, int b) {if ((mPrivateFlags3 & PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT) != 0) {onMeasure(mOldWidthMeasureSpec, mOldHeightMeasureSpec);mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;}...}
}

        这里有点令人疑惑,为什么在 measure 中跳过了 onMeasure,但又在 layout 中找补了回来。不执行可以优化性能耗时,但这里又重新执行了一次,优化在哪里?既然有这段代码,那么就一定是优化的,我们先有一下两种猜测:

  1. 前一次和后一次执行的逻辑不同,前一次的性能耗时长,后一次的性能耗时短,所以有优化。
  2. 优化了执行次数,前者执行次数比后者多。

        让我们先看一下引入 measureCache 的 commit message,看看作者怎么说的。

Skip unnecessary measurements when possible.

This change introduces a new measure cache to View, to remember the measured dimensions for previous pairs of measure specs. The measure cache is cleared whenever a View requests layout.

Unfortunately some Views rely on measure being always called when layout is invoked. To work around this problem, we need to remember when we hit the measure cache to force a call to measure just prior to calling onLayout(). This does not completely removes all measure calls but enough to optimize a number of layouts.

跳过不必要的 measure。这次改动针对 view 引入了新的measure 缓存,其可以记录已经测量过的measure specs。每次 view requestLayout的时候,都会清除 measure cache。

不幸的是,一些 view 在layout 调用的时候,总是需要 measure 调用。为了解决这个问题,我们需要在命中 measure 缓存的时候,强制在 OnLayout中调用  onMeasure。这种做法没有完全移除 measure 的调用,但是也已经足够优化一部分了。

跳过 onMeasure虽然可以提高效率,但是有一些自定义 view 是依赖其 onMeasure 流程保证其正常工作的。换句话说,一些自定义 View 的 onMeasure 方法不仅仅完成了可以被跳过的 measurement,还执行了某些不能被跳过的流程。 例如 ViewPager

public class ViewPager {protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// measure self and decor...// update childrenpopulate();// measure children...}
}

        ViewPager 依赖onMeasure 更新 page,如果 onMeasure 被跳过,就有可能出现 page 错位的情况。除了 ViewPager,RecyclerView、CoordinateLayout 等复杂度较高的组件也都在 onMeasure 中做了许多复杂的工作。既然 onMeasure 一定要执行,那么 measureCache 的优化工作又体现在哪里呢?毕竟 commit message 最后写了“but enough to optimize a number of layouts.” 

        measureCache 可以将一次 Traversal 中多次冗余 onMeasure 减少为一次,对于很多 ViewGroup,在 onMeasure 阶段往往会不止一次的调用 child 的 measure,例如RelativeLayout 、使用了 weight 的 LinearLayout、ConstraintLayout 等等,measureCache 的存在使得 child 本应该在 parent view onMeasure 阶段执行的多次 measure 被延后到 layout 阶段,且仅执行一次。

public class RelativeLayout extends ViewGroup {protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {measureChildHorizontal(child, params, myWidth, myHeight);measureChild(child, params, myWidth, myHeight);setMeasuredDimension(width, height);}
}

        假设 A、B、C 都是一个需要测量孩子两次的 ViewGroup,那么如果没有 MeasureCache,当执行 A 的 Measure 时候,将会调用 BBCC,共四次 measure,同样的调用DDEEDDEEFFGGFFGG,共 16 次 measure。但是如果有 measureCache,在 measure 阶段,将会调用 A 的 measure(如果 A 是顶 viewGroup),然后直接设置 B、C 的大小。只调用了 1 次。然后在 layout 阶段,调用一次 B 的 onMeasure、一次 C 的 onMeasure,DEFG 的 onMeasure 各一次。所以只调用了六次。已经足够优化了。 

http://www.yayakq.cn/news/648264/

相关文章:

  • 网站锚点链接怎么做kunkka wordpress
  • 深圳网站建设制作设计中小型网站建设流程
  • 推广平台免费重庆seo网站建设优化
  • 关于公司门户网站建设的议案高流量网站开发框架经验
  • 2019做网站必须做可信网站吗14版哥斯拉的官方做的宣传网站
  • 森网站建设廊坊seo优化排名
  • html5网站建设基本流程图网站内容由什么组成部分组成
  • 有什么网站开发软件有没有接做网站私活的平台
  • 松江做公司网站wordpress 不显示首页
  • 易无忧建站做推广一般那些网站比较好
  • 模板建站wordpress 商店主题
  • 西安做网站设计的公司甘德县公司网站建设
  • 北京建站优化公司短视频运营策划
  • 网站推广的作用是远程教育网站建设
  • 做室内设计特别好的网站php抽奖网站源码
  • 淮安市建设监理协会网站电子商务网站开发系统平台
  • 德阳定制建站网站建设制作信息网站开发合同
  • 网站开发盈利模式惠州seo报价
  • 谷歌站长平台php4.4 用什么wordpress
  • spark怎么做网站数据库网站开发人员配置
  • 网站建设专家证书互联网设计院
  • 南宁律师网站建设wordpress文章尾部
  • 做一个网站只做前端怎么做注册公司注册地址怎么弄
  • 长春建站模板源码商会网站制作
  • 杭州网站设计公司推荐母婴网站建设的与功能模块
  • 成都网站成都网站制作公司成都必去十大网红景点
  • 连云港网站建设费用行唐县网站建设
  • 作文网站投稿长沙专业做网络的公司
  • ps做购物小网站做照明出口的网站
  • 做网站代理拉别人网站wordpress 点赞打赏