java - 关于 View.onScrollChanged() 的来源

标签 java android view android-source

这里是 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

最佳答案

很可能,mAttachInfovolatile;那么ai的目的就是为了避免两个线程访问这个对象时出现NullPOinterExceptionmAttachInfo是检查mAttachInfo!=null<后写的 但在执行 mAttachInfo.mViewScrollChanged = true;

之前

关于java - 关于 View.onScrollChanged() 的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15406025/

相关文章:

python - 如何更改 view.py 中 django-tables2 表的列标题?

android - 如何为recyclerview中的每个列表项添加计数器计时器

java - 如何在JPA/Hibernate中根据两个外键生成id?

java - 在 Spring 中替换类别的标签系统 - Hibernate java 项目

android - 通过小米健身应用连接小米手环

android - 在 API 级别 17 从 Android 浏览器启动 Activity

java - Session.getAllTrackables 和 Frame.getUpdatedTrackables 有什么区别?

java - Linux下用Java写的如何创建带空格的文件夹?

Android 中的 Java Xml 解析器

安卓错误 : Only the original thread that created a view hierarchy can touch its views