2013-03-14 46 views
1

這裏是protected void View.onScrollChanged(int l, int t, int oldl, int oldt)來源:關於)View.onScrollChanged來源(

/** 
* 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

回答

3

最有可能的是,mAttachInfovolatile;那麼ai的目的是爲了避免NullPOinterException當兩個線程同時訪問該對象和mAttachInfo正在檢查mAttachInfo!=null之後,但在執行mAttachInfo.mViewScrollChanged = true;

+0

'mAttachInfo'以這種方式宣告以前寫的:'AttachInfo mAttachInfo;',所以它是不揮發。 ..但它似乎不應該是揮發性的描述行爲... – Prizoff 2013-03-14 11:44:16