Android视图中的默认overScrollMode值

时间:2014-11-11 18:53:23

标签: android-listview android-view android-overscoll

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

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

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

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

这是否意味着Android文档不正确?我是否必须明确将overScrollMode设置为' always'在我的列表视图中?

1 个答案:

答案 0 :(得分:4)

是的,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;
    }
}