# ohosWheelView **Repository Path**: HarmonyOS-tpc/ohosWheelView ## Basic Information - **Project Name**: ohosWheelView - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-06-26 - **Last Updated**: 2023-04-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 效果图如下: ## Download Gradle: ```groovy repositories { mavenCentral() } dependencies{ implementation 'io.openharmony.tpc.thirdlib:ohosWheelView:1.0.1' } ``` ### 常见问题 1. 设置初始位置:调用`setInitPosition()`,不是`setCurrentPosition()`。 1. 适配`setCurrentPosition(0)`的场景 2. 适配嵌套在`ScrollView`滑动冲突 3. 适配在`dialog`中显示 同时,提供各种参数接口,包括文本大小,显示数量,控件颜色等各种参数 #### Description of AttrSet | AttrSet | Format | Default | Description | | :-------------------: | :-----: | :--------: | :----------------: | | awv_textsize | integer | 15 | textsize | | awv_lineSpace | float | 2.0f | line space | | awv_centerTextColor | integer | oxff313131 | center text color | | awv_outerTextColor | integer | 0xffafafaf | outer text color | | awv_dividerTextColor | integer | oxff313131 | center text color | | awv_itemsVisibleCount | integer | 9 | visible item count | | awv_isLoop | boolean | true | is loop mode | ## 滚动效果类似一个圆柱 ## ### 绘制 ### 在onMeasure方法中计算控件宽和高以及初始化画笔 itemHeight = lineSpacingMultiplier * maxTextHeight 圆柱半圆周为itemHeight*(itemCount - 1) 计算出圆柱直径即为控件高度 在onTouchEvent方法中计算圆柱滚动距离totalScrollY ### 在onDraw方法中绘制控件 ### 计算滚动了多少个条目change = (int) ((float) totalScrollY / itemHeight); 计算当前条目位置preCurrentIndex(处理超出边界的情况) 计算滚动超出条目的位移: int j2 = (int) ((float) totalScrollY % itemHeight); 绘制各个条目: 计算条目弧度radian 计算图纸canvas偏移量 图中的弧度标错了,应该标它的补角,那样感觉不好理解,大家自行脑补一下 h2也标错了,画图的时候忘记考虑空白区域了,h2应该是文字高度的sin值 double h1 = Math.cos(radian) * (double) radius; double h2 = (Math.sin(radian) * (double) maxTextHeight) / 2D) int translateY = (int) ((double) radius h1 h2; 图纸延Y方向缩放,值为弧度radian的sin值(这样出来的效果就感觉是个圆柱) ### 最后分不同情况绘制各个条目 ### 1. 偏移量translateY y值小于第一条线firstLineY y值的并且偏移量translateY+maxTextHeight大于第一条线y值小于第一条线firstLineY y值的(即第一条线穿过该条目文字) 2. 条目文字穿过第二条线的情况 3. 条目刚好在两条线中间的 4. 其他情况 onTouchEvent方法,当手离开控件时开始平滑滚动控件 AnimatorValue处理惯性滑动