电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

View绘制流程样本

View绘制流程样本_第1页
1/21
View绘制流程样本_第2页
2/21
View绘制流程样本_第3页
3/21
下载后可任意编辑View 绘制流程第一步: 递归 measure 源码分析//final 方法, 子类不可重写public final void measure(int widthMeasureSpec, int heightMeasureSpec) {......//回调 onMeasure()方法onMeasure(widthMeasureSpec, heightMeasureSpec);}这个方法的两个参数都是父 View 传递过来的, 代表了父 view 的规格。她由两部分组成, 高 2 位表示 MODE, 低 30 位表示 size。//View 的 onMeasure 默认实现方法protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {setMeasuredDimension(下载后可任意编辑getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));}对于非 ViewGroup 的 View 而言, 经过调用上面默认的 onMeasure即可完成 View 的测量。setMeasuredDimension 函数是一个很关键的 函 数 , 它 完 成 了 对 View 的 成 员 变 量 mMeasuredWidth 和mMeasuredHeight 变量赋值。public static int getDefaultSize(int size, int measureSpec) {int result = size;//经过 MeasureSpec 解析猎取 mode 与 sizeint specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec);switch (specMode) {case MeasureSpec.UNSPECIFIED: result = size; break; case MeasureSpec.AT_MOST: case MeasureSpec.EXACTLY: result = specSize; break; }return result;下载后可任意编辑}protected int getSuggestedMinimumWidth() {return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth());}protected int getSuggestedMinimumHeight() {return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight());}在 ViewGroup 中 定 义 了 measureChildren, measureChild, measureChildWith-Margins 方法来对子视图进行测量, measureChildren 内部实质只是循环调用 measureChild。protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) { //猎取子视图的 LayoutParamsfinal MarginLayoutParams lp = ...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

View绘制流程样本

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部