Code Monkey home page Code Monkey logo

wheelpicker's People

Contributors

zyyoona7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wheelpicker's Issues

crash bug

java.lang.ArithmeticException: divide by zero
at com.zyyoona7.wheel.WheelView.getCurrentPosition + 1113(WheelView.java:1113)

滑动 选中失效

滑动 选中失效

部分机型 还是会偶尔出现滑动到某一项 点击确定按钮 取值不是滑动的那一项 是原来的选中数据

OnWheelChangedListener 回调BUG

问题1:
使用场景,滑动wheel选择数据,如果滑动未停止,或者未选中,禁用外部某个控件。
当我触摸Wheel滚动到我需要的position到中间选中那个Viwe时,这时手指再离开屏幕,onWheelSelected未执行,OnItemSelectedListener也未进入回调,但是这时getSelectedItemPosition是选中有正确结果的。
这时我只有进入onWheelScrollStateChanged方法判断state是否为SCROLL_STATE_IDLE来确定wheel停止了滚动,

问题2:
item textSize 设置同一个值,在Android 5.0及以上和在 5.0一下,显示效果不一样,在5.0以下,显示的item字体变得很大,测试设备为Android SDK X86模拟器

设置字体后文字就不居中了

//字体信息
Typeface typeface = FontCache.getTypeface("Digital-7Mono.ttf");
wheelSecond.setTypeface(typeface);
wheelSecond.setTextAlign(WheelView.TEXT_ALIGN_CENTER);

回调年份错误

DatePickerView控件设置dpv_showYear=false隐藏年份后 回调返回的年份错误
这个库是不维护了吗😂 之前提过其他问题的也没fix

setDateRange逻辑有问题

2.0.7最新版本,设置今天到30年后的今天这个范围,依然能够选择今年的前几个月的日期,需要滚动几次才能控制住。
Calendar today = Calendar.getInstance(); Calendar nextDay = Calendar.getInstance(); nextDay.add(Calendar.YEAR, 30); binding.timePickerView.setDateRange(today, nextDay, WheelView.OverRangeMode.HIDE_ITEM);

一个优化建议

WheelView 在滚动状态时调用 getSelectedItemPosition(), 会发现返回的值和用户看到的不一致. 建议在这个方法中, 先判断是否在滚动, 如果在滚动就返回 getCurrentPosition(), 否则返回 mSelectedItemPosition. getSelectedItemData() 同理.

Out-projected type 'WheelView<*>!' prohibits the use of 'public open fun setOnItemSelectedListener(onItemSelectedListener: WheelView.OnItemSelectedListener<T!>!): Unit defined in com.zyyoona7.wheel.WheelView'

mLoopView.setOnItemSelectedListener(WheelView.OnItemSelectedListener<String> { wheelView, data, position -> })
在kotlin 中给WheelView设置OnItemSelectedListener时报错,错误提示:
Out-projected type 'WheelView<*>!' prohibits the use of 'public open fun setOnItemSelectedListener(onItemSelectedListener: WheelView.OnItemSelectedListener<T!>!): Unit defined in com.zyyoona7.wheel.WheelView'

出现“divide by zero”错误并闪退了

写了个小Demo测试滑动效果,结果报错闪退

java.lang.ArithmeticException: divide by zero
        at com.zyyoona7.wheel.WheelView.getCurrentPosition(WheelView.java:1177)
        at com.zyyoona7.wheel.WheelView.observeItemChanged(WheelView.java:1055)
        at com.zyyoona7.wheel.WheelView.invalidateIfYChanged(WheelView.java:1044)
        at com.zyyoona7.wheel.WheelView.onTouchEvent(WheelView.java:948)
        at android.view.View.dispatchTouchEvent(View.java:11820)
  • 手机型号:Redmi6A
  • Android版本:8.1.0
  • AndroidStudio版本:3.4.2
  • gradle:3.4.1
  • kotlin:1.3.40
  • androidx:使用

测试代码:

val hourView: WheelView<String> = findViewById(R.id.hour)
hourView.data = arrayListOf("01", "02", "03", "04", "05", "06", "07", "08", "09", "10")
hourView.isCyclic = true
hourView.visibleItems = 5
<LinearLayout
            android:id="@+id/timepicker"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:background="@android:color/white"
            android:orientation="horizontal"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

        <com.zyyoona7.wheel.WheelView
                android:id="@+id/hour"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_weight="1"/>

        <com.zyyoona7.wheel.WheelView
                android:id="@+id/min"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_weight="1"/>
    </LinearLayout>

报错位置应该是在com.zyyoona7.wheel.WheelView的getCurrentPosition()方法

    /**
     * 根据偏移计算当前位置下标
     *
     * @return 偏移量对应的当前下标
     */
    private int getCurrentPosition() {
        int itemPosition;
        if (mScrollOffsetY < 0) {
            itemPosition = (mScrollOffsetY - mItemHeight / 2) / mItemHeight;
        } else {
            itemPosition = (mScrollOffsetY + mItemHeight / 2) / mItemHeight;
        }
        int currentPosition = itemPosition % mDataList.size(); //此处报错了
        if (currentPosition < 0) {
            currentPosition += mDataList.size();
        }

        return currentPosition;
    }

包太大了

你这包存的什么东西啊这么大,39.7mb?

在kotlin中使用时无法声明一个泛型的wheelview

用kotlin来写无法使用md中的写法,转换成kotlin之后无法通过编译
然后试图用以下方式
在头部
import com.zyyoona7.wheel.WheelView

然后
val wv=findViewById(R.id.wheelview)

但是提示One type argument expected for class WheelView<T : Any!>
所以在kotlin中怎么调用呢?因为是kotlin新手,所以搞不太清

快速上下滑动不灵敏

在 onTouchEvent 的 按下时, 应该重置快速滑动标记位
isFlingScroll = false;
本来打算提 PR, 但是没有权限, 分支推不上去

一个建议

希望DatePickerView控件能增加属性 设置最大和最小日期, 以外的日期不显示,原先setMaxSelectedDate设置日期后超出最大日期就自动滚到最大日期感觉体验不是很友好

setSelectedItemPosition在position为0的时候不回调setOnItemSelectedListener

是这样的,我有一个三级联动的列表

比如 地区列表,学校列表,班级列表

理想做法是
给学校列表对应的WheelView设置setOnItemSelectedListener,在listener内部设置班级列表的data,地区选择改变后,我学校列表重新setData,再调一下setSelectedItemPosition(position)就行了。

但是我发现这个calculateItemDistance计算Item之间差值的方法,在position为0的时候是0

int itemDistance = calculateItemDistance(position);
if (itemDistance == 0) {
    return;
}

这地方就直接返回了。
导致调用不了。
希望能解决这个问题,或者说有其他方式?

按理讲三级联动,我是可以在第一级ItemSelected和第二级ItemSelected的监听中都重新设置第三级的data,但是显得很笨。

滚轮文字不可见,但是可滑动,有回调

目前使用的是1.0.9的版本
debug了一下,布局重复测量的时候,在 onMeasure()realWidth 可能为0。导致 mMaxTextWidth 变成了0,文字显示不出来。
回退到1.0.8就正常了

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//Line Space算在了mItemHeight中
int height;
if (isCurved) {
height = (int) ((mItemHeight * mVisibleItems * 2 / Math.PI) + getPaddingTop() + getPaddingBottom());
} else {
height = mItemHeight * mVisibleItems + getPaddingTop() + getPaddingBottom();
}
int width = (int) (mMaxTextWidth + getPaddingLeft() + getPaddingRight() + mTextBoundaryMargin * 2);
if (isCurved) {
int towardRange = (int) (Math.sin(Math.PI / 48) * height);
width += towardRange;
}
setMeasuredDimension(resolveSizeAndState(width, widthMeasureSpec, 0),
resolveSizeAndState(height, heightMeasureSpec, 0));
}

可以实现封装的泛型类吗?

比如城市信息 有个id ,name 等字段封装成了Bean, 使用wheelpicker 可以直接使用,有相关回调回来取需要显示哪个字段。

滑动卡顿

在Dialog中,第一次初始化弹出,快速的去滑动,这时候整个条目是卡顿的,没有滑动效果

自定义divider

建议可以添加一个自定义divider的方法, 例如可以用图片, view来作为divider

wheelview设置循环滚动时的跳转问题

wheelview设置为可循环滚动后向上或向下滑动多几次,超出position * mItemHeight的几倍之后再调用setSelectedItemPosition来设置(isSmoothScroll为true)时就会滑动很久切换到对应值,这边重写了个方法

private int calculateItemDistanceCyclic(int position) {
        int offsetY = (position * mItemHeight - mScrollOffsetY) % (mDataList.size() * mItemHeight);
        if (offsetY <= 0) {
            return offsetY <= -(mDataList.size() * mItemHeight) / 2 ? (mDataList.size() * mItemHeight) - Math.abs(offsetY) : offsetY;
        } else {
            return offsetY >= (mDataList.size() * mItemHeight) / 2 ? -(mDataList.size() * mItemHeight - offsetY) : Math.abs(offsetY);
        }

    }

在setSelectedItemPosition里修改下在循环滚动的情况下调用:

 //item之间差值
        int itemDistance;
        if (isCyclic)
            itemDistance = calculateItemDistanceCyclic(position);
        else
            itemDistance = calculateItemDistance(position);

望采纳,谢谢

崩溃

setSelectedDate和setMaxSelectedDate都设置为2021-01-31

Back traces starts.
java.lang.IllegalArgumentException: maxSelectedPosition must be greater than minSelectedPosition in WheelView.
at com.zyyoona7.wheel.WheelView.V0(WheelView.kt:18)
at com.zyyoona7.picker.ex.WheelDayView.r1(WheelExtViews.kt:1)
at g.y.a.c.b.g(DatePickerHelper.kt:17)
at com.zyyoona7.wheel.WheelView.a1(WheelView.kt:12)
at com.zyyoona7.picker.ex.WheelYearView.n1(WheelExtViews.kt:1)
at com.zyyoona7.picker.ex.WheelYearView.o1(WheelExtViews.kt:1)
at g.y.a.c.b.e(DatePickerHelper.kt:1)
at g.y.a.c.b.setSelectedDate(DatePickerHelper.kt:7)
at com.zyyoona7.picker.DatePickerView.setSelectedDate(DatePickerView.kt:2)
at com.z.tzrl.popupview.DatePickerPopup.D(DatePickerPopup.kt:44)
at com.lxj.xpopup.core.BasePopupView.y(BasePopupView.java:7)
at com.lxj.xpopup.core.BasePopupView$b.run(BasePopupView.java:3)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7142)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
Back traces ends.

条目少的时候,会把内容滚消失

screenshot_20190122-110502
我只有三个条目,当上方或者下方有空白条目时,点空白处,会计算滚动.多次点击,内容会消失
int clickToCenterDistance = 0;
if (System.currentTimeMillis() - mDownStartTime <= DEFAULT_CLICK_CONFIRM) {
//处理点击滚动
//手指抬起的位置到中心的距离为滚动差值
clickToCenterDistance = (int) (event.getY() - mCenterY);
}
你这里是无限上滚或者下滚的.我没想到怎么处理,只好注释了
// clickToCenterDistance = (int) (event.getY() - mCenterY);,这样就去掉了点击事件
.版主试试看怎么解决下,谢谢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.