File tree Expand file tree Collapse file tree 4 files changed +17
-10
lines changed
app/src/main/java/com/bigkoo/pickerviewdemo
src/main/java/com/bigkoo/pickerview/lib Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ public void onClick(View v) {
78
78
private void initTimePicker () {
79
79
//控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
80
80
Calendar selectedDate = Calendar .getInstance ();
81
- /* selectedDate.set(2013,2,29);*/
81
+ selectedDate .set (2013 ,2 ,29 );
82
82
Calendar startDate = Calendar .getInstance ();
83
83
startDate .set (2013 ,1 ,23 );
84
84
Calendar endDate = Calendar .getInstance ();
Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ android {
12
12
defaultConfig {
13
13
minSdkVersion 9
14
14
targetSdkVersion 25
15
- versionCode 11
16
- versionName " 3.0.7 "
15
+ versionCode 12
16
+ versionName " 3.0.8 "
17
17
}
18
18
buildTypes {
19
19
release {
@@ -39,7 +39,7 @@ publish {
39
39
userOrg = ' contrarywind' // bintray.com 用户名/组织名 user/org name
40
40
groupId = ' com.contrarywind' // JCenter上显示的路径 path
41
41
artifactId = ' Android-PickerView' // 项目名称 project name
42
- publishVersion = ' 3.0.7 ' // 版本号 version code
42
+ publishVersion = ' 3.0.8 ' // 版本号 version code
43
43
desc = ' this is a pickerview for android' // 项目描述 description
44
44
website = ' https://github.com/Contrarywind/Android-PickerView' // 项目网址链接 link
45
45
}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public final void run() {
21
21
if (realTotalOffset == Integer .MAX_VALUE ) {
22
22
realTotalOffset = offset ;
23
23
}
24
- //把要滚动的范围细分成十小份,按是小份单位来重绘
24
+ //把要滚动的范围细分成10小份,按10小份单位来重绘
25
25
realOffset = (int ) ((float ) realTotalOffset * 0.1F );
26
26
27
27
if (realOffset == 0 ) {
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ void smoothScroll(ACTION action) {
251
251
cancelFuture ();
252
252
if (action == ACTION .FLING || action == ACTION .DAGGLE ) {
253
253
mOffset = (int ) ((totalScrollY % itemHeight + itemHeight ) % itemHeight );
254
- if ((float ) mOffset > itemHeight / 2.0F ) {
254
+ if ((float ) mOffset > itemHeight / 2.0F ) {//如果超过Item高度的一半,滚动到下一个Item去
255
255
mOffset = (int ) (itemHeight - (float ) mOffset );
256
256
} else {
257
257
mOffset = -mOffset ;
@@ -606,13 +606,20 @@ public boolean onTouchEvent(MotionEvent event) {
606
606
break ;
607
607
//完成滑动,手指离开屏幕
608
608
case MotionEvent .ACTION_UP :
609
+
609
610
default :
610
- if (!eventConsumed ) {
611
+ if (!eventConsumed ) {//屏幕点击或者拖拽事件
611
612
float y = event .getY ();
612
- double l = Math .acos ((radius - y ) / radius ) * radius ;
613
- int circlePosition = (int ) ((l + itemHeight / 2 ) / itemHeight );
614
-
613
+ // 由于之前是有向右偏移90度,所以 实际弧度范围为α2 =π/2-α (α=[0,π])
614
+ // 根据cosα = sin(π/2-α)
615
+ // (radius - y) / radius = sinα2 = sin(π/2-α) = cosα
616
+ // arccos(cosα)= α
617
+ // 所以 弧长 L = α*R
618
+ double L = Math .acos ((radius - y ) / radius ) * radius ;
619
+ //item0 有一半是在不可见区域,所以需要加上 itemHeight / 2
620
+ int circlePosition = (int ) ((L + itemHeight / 2 ) / itemHeight );
615
621
float extraOffset = (totalScrollY % itemHeight + itemHeight ) % itemHeight ;
622
+ //已滑动的弧长值
616
623
mOffset = (int ) ((circlePosition - itemsVisible / 2 ) * itemHeight - extraOffset );
617
624
618
625
if ((System .currentTimeMillis () - startTime ) > 120 ) {
You can’t perform that action at this time.
0 commit comments