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

おそらく、そうmAttachInfoですvolatile。の目的は、2 つのスレッドがこのオブジェクトにアクセスし、チェック後、実行前に書き込まaiれることを回避することです。NullPOinterExceptionmAttachInfomAttachInfo!=nullmAttachInfo.mViewScrollChanged = true;

于 2013-03-14T10:22:23.130 に答える