3

根据 Android文档,overScrollMode 的默认值为 OVER_SCROLL_ALWAYS。

但我的 ListView 似乎没有遵循这种行为。只有当列表中有足够的内容可以滚动时,它才会显示过度滚动行为。

我试图查看 Android 代码,发现在 View.java ref中 overScrollMode 设置为 OVER_SCROLL_IF_CONTENT_SCROLLS

我还检查了 ListView 和 AbsListView 的代码,以检查是否在任何地方设置了 overscrollmode,但我找不到任何东西。唯一设置 overScrollMode 的地方是在 View.java 中。

这是否意味着 Android 文档不正确?我是否必须在列表视图中将 overScrollMode 显式设置为“始终”?

4

1 回答 1

6

是的,Android 文档实际上是不正确的。我确认了。正如您在以下 Android 源代码中看到的那样,默认情况下过度滚动设置为if_content_scrolls

/**
 * Simple constructor to use when creating a view from code.
 *
 * @param context The Context the view is running in, through which it can
 *        access the current theme, resources, etc.
 */
public View(Context context) {
    mContext = context;
    mResources = context != null ? context.getResources() : null;
    mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED;
    // Set some flags defaults
    mPrivateFlags2 =
        (LAYOUT_DIRECTION_DEFAULT << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) |
        (TEXT_DIRECTION_DEFAULT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) |
        (PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT) |
        (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) |
        (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) |
        (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS);
    mUserPaddingStart = UNDEFINED_PADDING;
    mUserPaddingEnd = UNDEFINED_PADDING;

    if (!sCompatibilityDone && context != null) {
        final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;

        // Older apps may need this compatibility hack for measurement.
        sUseBrokenMakeMeasureSpec = targetSdkVersion <= JELLY_BEAN_MR1;

        // Older apps expect onMeasure() to always be called on a layout pass, regardless
        // of whether a layout was requested on that View.
        sIgnoreMeasureCache = targetSdkVersion < KITKAT;

        sCompatibilityDone = true;
    }
}
于 2014-11-24T23:45:16.173 回答