# NumberPickerView **Repository Path**: chinasoft5_ohos/NumberPickerView ## Basic Information - **Project Name**: NumberPickerView - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-11 - **Last Updated**: 2024-06-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # NumberPickerView #### 项目介绍 - 项目名称:NumberPickerView - 所属系列:openharmony的第三方组件适配移植 - 功能:一个在OHOS平台上具有更灵活属性的NumberPicker - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio 2.2 Beta1 - 基线版本:1.2.0 #### 效果演示 ![](/img/demo.gif) #### 安装教程 1.在项目根目录下的build.gradle文件中, ``` repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } } ``` 2.在entry模块的build.gradle文件中, ``` dependencies { implementation 'com.gitee.chinasoft_ohos:NumberPickerView:0.0.1-SNAPSHOT' } ``` 在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 **XML** ```xml ``` 在XML中使用以下属性 | Properties | Type | Introduce | | -------------------------------------------- | --------- | ------------ | | `npv_ShownCount` | integer | 显示的条目个数,默认3个 | | `npv_ShowDivider` | boolean | 是否显示两条divider,默认显示 | | `npv_DividerColor` | color | 两条divider的颜色 | | `npv_DividerMarginLeft` | dimension | divider距左侧的距离 | | `npv_DividerMarginRight` | dimension | divider距右侧的距离 | | `npv_DividerHeight` | dimension | divider的高度 | | `npv_TextColorNormal` | color | 未选中文字的颜色 | | `npv_TextColorSelected` | color | 选中文字的颜色 | | `npv_TextColorHint` | color | 中间偏右侧说明文字的颜色 | | `npv_TextSizeNormal` | dimension | 未选中文字的大小 | | `npv_TextSizeSelected` | dimension | 选中文字的大小 | | `npv_TextSizeHint` | dimension | 说明文字的大小 | | `npv_TextArray` | strarray | 文字内容 | | `npv_MinValue` | integer | 最小值,同setMinValue() | | `npv_MaxValue` | integer | 最大值,同setMaxValue() | | `npv_WrapSelectorWheel` | boolean | 设置是否wrap,同setWrapSelectorWheel | | `npv_HintText` | string | 设置说明文字 | | `npv_EmptyItemHint` | string | 空行的显示文字,默认不显示任何文字。只在WrapSelectorWheel==false是起作用 | | `npv_MarginStartOfHint` | dimension | 说明文字距离左侧的距离,"左侧"是指文字array最宽item的右侧 | | `npv_MarginEndOfHint` | dimension | 说明文字距离右侧的距离 | | `npv_ItemPaddingHorizontal` | dimension | item的水平padding,用于match_content模式 | | `npv_ItemPaddingVertical` | dimension | item的竖直padding,用于match_content模式 | | `npv_RespondChangeOnDetached` | boolean | 在detach时如果NumberPickerView正好滑动,设置是否响应onValueChange回调 | | `npv_RespondChangeInMainThread` | boolean | 指定`onValueChanged`响应事件在什么线程中执行 | | `npv_AlternativeTextArrayWithMeasureHint` | string | 可能达到的最大宽度,包括说明文字在内,最大宽度只可能比此String的宽度更大 | | `npv_AlternativeTextArrayWithoutMeasureHint` | string | 可能达到的最大宽度,不包括说明文字在内,最大宽度只可能比此String的宽度+说明文字+说明文字marginstart +说明文字marginend 更大 | | `npv_AlternativeHint` | string | 说明文字的最大宽度 | **JAVA** 1)若设置的数据(String[] mDisplayedValues)不会再次改变,可以使用如下方式进行设置:(与NumberPicker的设置方式一致) ```java picker.setMinValue(minValue); picker.setMaxValue(maxValue); picker.setValue(value); ``` 2)若设置的数据(String[] mDisplayedValues)会改变,可以使用如下组合方式进行设置:(与NumberPicker的更改数据方式一致) ```java int minValue = getMinValue(); int oldMaxValue = getMaxValue(); int oldSpan = oldMaxValue - minValue + 1; int newMaxValue = display.length - 1; int newSpan = newMaxValue - minValue + 1; if (newSpan > oldSpan) { setDisplayedValues(display); setMaxValue(newMaxValue); } else { setMaxValue(newMaxValue); setDisplayedValues(display); } ``` 或者直接使用NumberPickerView提供的方法:
`refreshByNewDisplayedValues(String[] display)`
使用此方法时需要注意保证数据改变前后的minValue值不变,以及设置的display不能够为null,且长度不能够为0。 3)添加了滑动过程中响应value change的函数 ```java picker.setOnValueChangeListenerInScrolling(...); ``` ## 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 ## 版本迭代 - 0.0.1-SNAPSHOT ## 版权和许可信息 Copyright 2016 Carbs.Wang (NumberPickerView) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.