我是靠谱客的博主 义气山水,这篇文章主要介绍NumberPicker循环滚动,现在分享给大家,希望可以做个参考。

使用setWrapSelectorWheel(boolean wrapSelectorWheel) 设置是否循环滚动。而且必须在setMaxValue()setMinValue() 的后面调用setWrapSelectorWheel() 才管用。
官方文档说明如下:
这里写图片描述

接下来我们看一下源代码。
setMaxValue()setMinValue()中调用了setWrapSelectorWheel() 。判断(mMaxValue - mMinValue)是否大于3(SELECTOR_WHEEL_ITEM_COUNT),如果大于3,则循环滚动。

    private static final int SELECTOR_WHEEL_ITEM_COUNT = 3;

    private final int[] mSelectorIndices = new int[SELECTOR_WHEEL_ITEM_COUNT];

    /**
     * Sets the max value of the picker.
     *
     * @param maxValue The max value inclusive.
     *
     * <strong>Note:</strong> The length of the displayed values array
     * set via {@link #setDisplayedValues(String[])} must be equal to the
     * range of selectable numbers which is equal to
     * {@link #getMaxValue()} - {@link #getMinValue()} + 1.
     */
    public void setMaxValue(int maxValue) {
        if (mMaxValue == maxValue) {
            return;
        }
        ......
        boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
        setWrapSelectorWheel(wrapSelectorWheel);
        ......
        invalidate();
    }

    /**
     * Sets the min value of the picker.
     *
     * @param minValue The min value inclusive.
     *
     * <strong>Note:</strong> The length of the displayed values array
     * set via {@link #setDisplayedValues(String[])} must be equal to the
     * range of selectable numbers which is equal to
     * {@link #getMaxValue()} - {@link #getMinValue()} + 1.
     */
    public void setMinValue(int minValue) {
        if (mMinValue == minValue) {
            return;
        }
        ......
        boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
        setWrapSelectorWheel(wrapSelectorWheel);
        ......
        invalidate();
    }

最后

以上就是义气山水最近收集整理的关于NumberPicker循环滚动的全部内容,更多相关NumberPicker循环滚动内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(120)

评论列表共有 0 条评论

立即
投稿
返回
顶部