提醒:下面源码来自SDK里Android-34版本
一、requestLayout
1.1 requestLayout方法源码
/**
* Call this when something has changed which has invalidated the
* layout of this view. This will schedule a layout pass of the view
* tree. This should not be called while the view hierarchy is currently in a layout
* pass ({
@link #isInLayout()}. If layout is happening, the request may be honored at the
* end of the current layout pass (and then layout will run again) or after the current
* frame is drawn and the next layout occurs.
*
* <p>Subclasses which override this method should call the superclass method to
* handle possible request-during-layout errors correctly.</p>
* 上面翻译
* 当某些东西发生改变使。无效时调用这个
* 这个视图的布局。这将安排视图的布局传递树。
* 当视图层次结构当前处于布局时,不应该调用这个函数
* pass ({
@link #isInLayout()})。如果正在进行布局,
* 请求可能会在结束当前布局传递(然后布局将再次运行)
* 或在当前绘制框架,并发生下一个布局。
*
* 重写此方法的子类应该调用父类方法正确处理布局期间可能出现的请求错误。
*/
@CallSuper
public void requestLayout() {
if (isRelayoutTracingEnabled()) {
Trace.instantForTrack(TRACE_TAG_APP, "requestLayoutTracing",
mTracingStrings.classSimpleName);
printStackStrace(mTracingStrings.requestLayoutStacktracePrefix);
}
if (mMeasureCache != null) mMeasureCache.clear();
if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) {
// Only trigger request-during-layout logic if this is the view requesting it,
// not the views in its parent hierarchy
ViewRootImpl viewRoot = getViewRootImpl();
if (viewRoot != null && viewRoot.isInLayout()) {
if (!viewRoot.requestLayoutDuringLayout(this)) {
return;
}
}
mAttachInfo.mViewRequestingLayout = this;
}
mPrivateFlags |= PFLAG_FORCE_LAYOUT;
mPrivateFlags |= PFLAG_INVALIDATED;
if (mParent != null && !mParent.isLayoutRequested()) {
mParent.requestLayout();
}
if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == this) {
mAttachInfo.mViewRequestingLayout = null;
}
}
1.2 requestLayoutDuringLayout方法源码
/**
* Called by {
@link android.view.View#requestLayout()} if the view hierarchy is currently
* undergoing a layout pass. requestLayout(


最低0.47元/天 解锁文章
502

被折叠的 条评论
为什么被折叠?



