zyyoona7 / wheelpicker Goto Github PK
View Code? Open in Web Editor NEWA smooth, highly customizable wheel view and picker view, support 3D effects like iOS. 一个顺滑的、高度自定义的滚轮控件和选择器,支持类似 iOS 的 3D 效果
License: Apache License 2.0
A smooth, highly customizable wheel view and picker view, support 3D effects like iOS. 一个顺滑的、高度自定义的滚轮控件和选择器,支持类似 iOS 的 3D 效果
License: Apache License 2.0
DatePickerView 设置显示条目为3时,没有滑动到当前日期
显示日期为数据源的第一条,没有显示当前日期
感谢大佬,大佬辛苦了
目前想法做一个半圆形的选择器,所以想到是否有横向的WheelView
java.lang.ArithmeticException: divide by zero
at com.zyyoona7.wheel.WheelView.getCurrentPosition + 1113(WheelView.java:1113)
比如定义一个圆角的 shape
@zyyoona7
连这个回调都不进啊,更新了1.0.7还是一样
wheelView.setOnItemSelectedListener { _, data, p ->
// age=
this.data = data.toString().split("元")[0].toInt()
}
滑动 选中失效
部分机型 还是会偶尔出现滑动到某一项 点击确定按钮 取值不是滑动的那一项 是原来的选中数据
您好 有禁止滑动的方法吗
版本:com.github.zyyoona7:wheelview:1.0.7
wv_selectedItemTextColor 无效
问题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
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() 同理.
滑动到2020,手放开,自动跳到2018
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'
写了个小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)
测试代码:
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来写无法使用md中的写法,转换成kotlin之后无法通过编译
然后试图用以下方式
在头部
import com.zyyoona7.wheel.WheelView
然后
val wv=findViewById(R.id.wheelview)
但是提示One type argument expected for class WheelView<T : Any!>
所以在kotlin中怎么调用呢?因为是kotlin新手,所以搞不太清
如题,在非3D情况下,有时会用到这个设置
比如每个选项的高度,每个选项中间有一条间隔线等?
如何把滑动的文字换成图片
在 onTouchEvent 的 按下时, 应该重置快速滑动标记位
isFlingScroll = false;
本来打算提 PR, 但是没有权限, 分支推不上去
在给控件设置一个 size为0的list时会出现java.lang.ArithmeticException divide by zero 错误 #20
我觉得这里应该加一个 是否大于0的判断
能否添加一个让选中的条目字体加粗,刚好遇到这样的需求。
辛苦了。。。。。
希望DatePickerView控件能增加属性 设置最大和最小日期, 以外的日期不显示,原先setMaxSelectedDate设置日期后超出最大日期就自动滚到最大日期感觉体验不是很友好
华为Meta20滑动停止后无法即刻获取值;
在滑动停止后需要等待1s左右才能有值。
会导致选择年份自动跳转到最小年份
是这样的,我有一个三级联动的列表
比如 地区列表,学校列表,班级列表
理想做法是
给学校列表对应的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就正常了
WheelPicker/wheelview/src/main/java/com/zyyoona7/wheel/WheelView.java
Lines 369 to 385 in d1c3f71
How do I set custom font from otf/ttf files in assets folder?
每次滑动后重置后面到顶部的属性时什么,设置了setResetSelectedPosition没用
比如城市信息 有个id ,name 等字段封装成了Bean, 使用wheelpicker 可以直接使用,有相关回调回来取需要显示哪个字段。
java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
at java.util.ArrayList.get(ArrayList.java:439)
at com.zyyoona7.wheel.WheelView.run(WheelView.java:1144)
在Dialog中,第一次初始化弹出,快速的去滑动,这时候整个条目是卡顿的,没有滑动效果
建议可以添加一个自定义divider的方法, 例如可以用图片, view来作为divider
能支持Androidx吗
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.
我只有三个条目,当上方或者下方有空白条目时,点空白处,会计算滚动.多次点击,内容会消失
int clickToCenterDistance = 0;
if (System.currentTimeMillis() - mDownStartTime <= DEFAULT_CLICK_CONFIRM) {
//处理点击滚动
//手指抬起的位置到中心的距离为滚动差值
clickToCenterDistance = (int) (event.getY() - mCenterY);
}
你这里是无限上滚或者下滚的.我没想到怎么处理,只好注释了
// clickToCenterDistance = (int) (event.getY() - mCenterY);,这样就去掉了点击事件
.版主试试看怎么解决下,谢谢
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.