位置: 编程技术 - 正文

Android View的刷新机制(android recycleview 刷新)

编辑:rootadmin

推荐整理分享Android View的刷新机制(android recycleview 刷新),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:android页面刷新,android页面刷新,android recyclerview刷新,android webview刷新,android view 刷新,android recycleview 刷新,android刷新listview,android view 刷新,内容如对您有帮助,希望把文章链接给更多的朋友!

在Android的布局体系中,父View负责刷新、布局显示子View;而当子View需要刷新时,则是通知父View来完成。这种处理逻辑在View的代码中明确的表现出来:

public void invalidate() { final ViewParent p = mParent; final AttachInfo ai = mAttachInfo; if (p != null && ai != null) { final Rect r = ai.mTmpInvalRect; // 设置刷新区域为自己的尺寸 r.set(0, 0, mRight - mLeft, mBottom - mTop); p.invalidateChild(this, r); } }

子View调用invalidate时,首先找到自己父View(View的成员变量mParent记录自己的父View),然后将AttachInfo中保存的信息告诉父View刷新自己。

View的父子关系的建立分为两种情况:

1) View加入ViewGroup中

private void addViewInner(View child, int index, LayoutParams params, booleanpreventRequestLayout) { ..... // tell our children if (preventRequestLayout) { child.assignParent(this); } else { child.mParent = this; } ..... }

2)DecorView注册给WindowManagerImpl时,产生一个ViewRoot作为其父View。

public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView){ ..... view.assignParent(this); .... }

AttachInfo是在View第一次attach到Window时,ViewRoot传给自己的子View的。这个AttachInfo之后,会顺着布局体系一直传递到最底层的View。

View.java

void dispatchAttachedToWindow(AttachInfo info, int visibility) { mAttachInfo = info; ..... }Android View的刷新机制(android recycleview 刷新)

ViewGroup.java

void dispatchAttachedToWindow(AttachInfo info, int visibility) { super.dispatchAttachedToWindow(info, visibility); for (int i = 0; i < count; i&#;&#;) { children[i].dispatchAttachedToWindow(info, visibility); } }

并且在新的View被加入ViewGroup时,也会将该AttachInfo传给加入的View

ViewGroup.java

private void addViewInner(View child, int index, LayoutParams params, booleanpreventRequestLayout) { child.dispatchAttachedToWindow(mAttachInfo, (mViewFlags&VISIBILITY_MASK)); }

到这里明白了mParent与AttachInfo代表的意义,可以继续刷新过程的分析。

在invalidate中,调用父View的invalidateChild,这是一个从第向上回溯的过程,每一层的父View都将自己的显示区域与传入的刷新Rect做交集。

public final void invalidateChild(View child, final Rect dirty) { ViewParent parent = this; final AttachInfo attachInfo = mAttachInfo; if (attachInfo != null) { final int[] location = attachInfo.mInvalidateChildLocation; // 需要刷新的子View的位置 location[CHILD_LEFT_INDEX] = child.mLeft; location[CHILD_TOP_INDEX] = child.mTop; // If the child is drawing an animation, we want to copy this flag onto // ourselves and the parent to make sure the invalidate request goes through final boolean drawAnimation = (child.mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION; // Check whether the child that requests the invalidate is fully opaque final boolean isOpaque = child.isOpaque() && !drawAnimation && child.getAnimation() != null; // Mark the child as dirty, using the appropriate flag // Make sure we do not set both flags at the same time final int opaqueFlag = isOpaque ? DIRTY_OPAQUE : DIRTY; do { View view = null; if (parent instanceof View) { view = (View) parent; } if (drawAnimation) { if (view != null) { view.mPrivateFlags |= DRAW_ANIMATION; } else if (parent instanceof ViewRoot) { ((ViewRoot) parent).mIsAnimating = true; } } // If the parent is dirty opaque or not dirty, mark it dirty with the opaque // flag coming from the child that initiated the invalidate if (view != null && (view.mPrivateFlags & DIRTY_MASK) != DIRTY) { view.mPrivateFlags = (view.mPrivateFlags & ~DIRTY_MASK) | opaqueFlag; } parent = parent.invalidateChildInParent(location, dirty); } while (parent != null); } } public ViewParent invalidateChildInParent(final int[] location, final Rect dirty) { if ((mPrivateFlags & DRAWN) == DRAWN) { if ((mGroupFlags & (FLAG_OPTIMIZE_INVALIDATE | FLAG_ANIMATION_DONE)) != FLAG_OPTIMIZE_INVALIDATE) { // 根据父View的位置,偏移刷新区域 dirty.offset(location[CHILD_LEFT_INDEX] - mScrollX, location[CHILD_TOP_INDEX] - mScrollY); final int left = mLeft; final int top = mTop; //计算实际可刷新区域 if (dirty.intersect(0, 0, mRight - left, mBottom - top) || (mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION) { mPrivateFlags &= ~DRAWING_CACHE_VALID; location[CHILD_LEFT_INDEX] = left; location[CHILD_TOP_INDEX] = top; return mParent; } } else { mPrivateFlags &= ~DRAWN & ~DRAWING_CACHE_VALID; location[CHILD_LEFT_INDEX] = mLeft; location[CHILD_TOP_INDEX] = mTop; dirty.set(0, 0, mRight - location[CHILD_LEFT_INDEX], mBottom - location[CHILD_TOP_INDEX]); return mParent; } } return null; }

这个向上回溯的过程直到ViewRoot那里结束,由ViewRoot对这个最终的刷新区域做刷新。

ViewRoot.java

public void invalidateChild(View child, Rect dirty) { scheduleTraversals(); }原文出至:

android 一个绚丽的loading动效分析与实现! 尊重原创,欢迎转载,转载请注明:

Android闹钟 AlarmManager的使用 转自:

Android的图片,字符串,demin,color,以及Array,boolean,Integer资源的使用-android学习之旅(五十四) 总体介绍颜色值的定义定义字符串,颜色,尺寸资源字符串颜色资源尺寸资源使用字符串,颜色,尺寸资源boolean的定义与使用整形常量的定义与使用数

标签: android recycleview 刷新

本文链接地址:https://www.jiuchutong.com/biancheng/374410.html 转载请保留说明!

上一篇:android PercentRelativeLayout 支持百分比来设置控件的宽高

下一篇:android 一个绚丽的loading动效分析与实现!

  • 契税是什么样的单子
  • 实收资本的期末余额在借方还是贷方
  • 公司支付宝账户要交税吗
  • 小规模季超30万,蔬菜还免增值税吗
  • 有没有退股一说
  • 待摊费用可以转入固定资产吗
  • 企业奖励的目的
  • 有现金折扣方式有哪些
  • 承付期满日怎么算
  • 将资产货物用于业务宣传增值税
  • 应收账款平均余额公式
  • 出口发票税率怎么开
  • 福利费要交个人税吗
  • 进项税核定扣除试点
  • 以下凭证免征印花税的有
  • 挂靠行为应当如何纳税?
  • 月销售额小于10万的一般纳税人减免
  • 进项税额能抵扣的几种情形
  • 预付账款收不到发票怎么冲账
  • 纺织厂收购棉花如何计税?
  • 滞留海关发票是谁开
  • 计提劳务派遣人数怎么算
  • php数组函数,选班长
  • PHP:escapeshellcmd()的用法_命令行函数
  • 今天春节是什么生肖
  • 国家规定不计入社保基数
  • windows环境下,ping的功能和使用方法
  • 有限公司股权转让怎么办理流程
  • vue项目难点及解决方法
  • fall 瀑布
  • 视图的定义和操作实验报告
  • pythonnetworkx
  • echarts series name
  • 装修费用记什么科目
  • 电影院是否征收文化建设事业费
  • 新成立的公司的搭建费可以申请补助吗?
  • 著作权费用
  • 印花税没交会怎么样
  • 待处理财产损溢增加是哪方
  • 税控盘没有报税处理这个选项
  • 进口关税账务处理办法
  • 销售费用工资是什么科目
  • sqlserver2008r2怎么使用
  • 个人所得税9月初申报哪个月的
  • 购买材料增值税税率
  • 个体户与公司的差别
  • 使用积分换取物的软件
  • 开了假发票什么后果?
  • 贷款保险费由谁承担
  • 专用发票怎么网上申领
  • 会计核算方法包括
  • 设计会计凭证
  • mysql5.7慢查询
  • windows任务管理器打不开
  • win10右键菜单自定义
  • 面向小微企业
  • macos safari无法使用
  • ubuntu操作系统入门
  • windows7显示桌面的操作方法
  • win8 更改电脑设置
  • linux系统漏洞总结
  • window八
  • 怎么更换win系统
  • [置顶]公主大人接下来是拷问时间31
  • 电脑自动重启命令
  • android反编译smali
  • textview不换行
  • cmd 更改密码
  • 对xmlHttp对象方法和属性的理解
  • unityui渲染顺序
  • javascript入门教程
  • python str()怎么用
  • jquery给div添加样式
  • Android之Notification
  • 方块大作战百科
  • 审计会计税务的区别及联系
  • 河北税务云办税厅官方
  • 甘肃增值税发票查验平台官网
  • 药店开给个人的增值税发票是什么样
  • 增值税发票冲红是什么意思
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设