在Android的布局体系中,父View负责刷新、布局显示子View;而当子View需要刷新时,则是通知父View来完成。
步骤就是:
1、调用子View的invalidate()
2、跳转到上一层的invalidateChild函数中区
3、在一次调用invalidateChildInParent的函数一次层层刷新
4、具体的刷新后续操作,我就不清楚了,调用invalidate最终在代码上就在invalidateChild终止了的,所以表示有点点不清晰,求各位大牛介绍一下吧。。。。。?在此谢过了。。
让我来阅读源代码:
首先在View类中:
/**
* Invalidate the whole view. If the view is visible,
{@link
#onDraw} 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() {
if (ViewDebug.TRACE_HIERARCHY) {
ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE);
}
if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS)) {
mPrivateFlags &= ~DRAWN & ~DRAWING_CACHE_VALID;
final ViewParent p = mParent; //获得父类View的对象
final AttachInfo ai = mAttachInfo;//获得匹配
if (p != null && ai != null) {
final Rect r = ai.mTmpInvalRect;
r.set(0, 0, mRight – mLeft, mBottom – mTop);//设置本View的尺寸