android-invalidate()源码
2016-06-30 16:09
393 查看
/** * Invalidate the whole view. If the view is visible, * {@link #onDraw(android.graphics.Canvas)} will be called at some point in * the future. This must be called from a UI thread. To call from a non-UI thread, * call {@link #postInvalidate()}. */ public void invalidate() { invalidate(true); }
个人理解是如果在调用这个方法时,view是可见的,则刷新他。。。重新调用onDraw()方法,重绘页面。这个方法必须在UI线程里面。如果是非UI线程可以使用postInvalidate()
下面是带参数方法的原码(太多看不懂。。。,一个View类加注释2W行,确实有点。。。):
/** * This is where the invalidate() work actually happens. A full invalidate() * causes the drawing cache to be invalidated, but this function can be called with * invalidateCache set to false to skip that invalidation step for cases that do not * need it (for example, a component that remains at the same dimensions with the same * content). * * @param invalidateCache Whether the drawing cache for this view should be invalidated as * well. This is usually true for a full invalidate, but may be set to false if the * View's contents or dimensions have not changed. */ void invalidate(boolean invalidateCache) { if (skipInvalidate()) { return; } if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || (invalidateCache && (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID) || (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED || isOpaque() != mLastIsOpaque) { mLastIsOpaque = isOpaque(); mPrivateFlags &= ~PFLAG_DRAWN; mPrivateFlags |= PFLAG_DIRTY; if (invalidateCache) { mPrivateFlags |= PFLAG_INVALIDATED; mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; } final AttachInfo ai = mAttachInfo; final ViewParent p = mParent; //noinspection PointlessBooleanExpression,ConstantConditions if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { if (p != null && ai != null && ai.mHardwareAccelerated) { // fast-track for GL-enabled applications; just invalidate the whole hierarchy // with a null dirty rect, which tells the ViewAncestor to redraw everything p.invalidateChild(this, null); return; } } if (p != null && ai != null) { final Rect r = ai.mTmpInvalRect; r.set(0, 0, mRight - mLeft, mBottom - mTop); // Don't call invalidate -- we don't want to internally scroll // our own bounds p.invalidateChild(this, r); } } }
View.java原码:点击下载链接
相关文章推荐
- AndroidSweetSheet:ViewPager的实现(2)
- AndroidSweetSheet:ViewPager的实现(2)
- android 百度地图系列之地图初始化及定位
- android屏幕适配
- 短信管理器(SmsManager)
- Android开发学习之路-带文字的图片分享
- android studio 的oncreate 的 PersistableBundle persistentState
- Activity的生命周期理解笔记
- Android Studio插件整理
- 【Android】熟悉Android Studio以及其快捷键
- android 6.29coolWeather开发过程
- Android数据存储之Internal Storage内部存储
- Android 主题设计全解析
- android-Paint-getTextBounds参数详解
- 开发中最常用的GitHub上 优秀的 Android 开源项目整理(精品)
- Android基础----ContentProvider
- android 拍照和选择相册图片剪切
- Android 版本检测更新
- Android中关闭应用的三种方式
- Android的Fragment使用总结