1

以下是 的来源protected void View.onScrollChanged(int l, int t, int oldl, int oldt)

/**
 * This is called in response to an internal scroll in this view (i.e., the
 * view scrolled its own contents). This is typically as a result of
 * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been
 * called.
 *
 * @param l Current horizontal scroll origin.
 * @param t Current vertical scroll origin.
 * @param oldl Previous horizontal scroll origin.
 * @param oldt Previous vertical scroll origin.
 */
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    if (AccessibilityManager.getInstance(mContext).isEnabled()) {
        postSendViewScrolledAccessibilityEventCallback();
    }

    mBackgroundSizeChanged = true;

    final AttachInfo ai = mAttachInfo;
    if (ai != null) {
        ai.mViewScrollChanged = true;
    }
}

问题是关于这一行:final AttachInfo ai = mAttachInfo;. 引入的目的ai是什么以及为什么要制作它final

4

1 回答 1

3

最有可能的mAttachInfovolatile;那么 的目的ai是避免NullPOinterException当两个线程访问这个对象并mAttachInfo在检查之后mAttachInfo!=null但在执行之前写入mAttachInfo.mViewScrollChanged = true;

于 2013-03-14T10:22:23.130 回答