5 Star 2 Fork 0

HarmonyOS-TPC / RulerView

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

该三方开源库从github fork过来

fork地址:https://github.com/zjun615/RulerView

fork版本号/日期:0.9.9 / 2021/1/28

RuleView

一系列卷尺控件,包含:基本卷尺控件(体重尺,或其它)、金额卷尺控件、时间卷尺控件

demo中,分别用三个控件,高仿了薄荷健康的体重尺、团贷网的金额尺、海康威视下萤石云视频的时间尺

添加依赖:

方式一: 添加har包到lib文件夹内 在entry的gradle内添加如下代码 implementation fileTree(dir: 'libs', include: ['.jar', '.har'])

方式二: allprojects { repositories{ mavenCentral() } }

implementation 'io.openharmony.tpc.thirdlib:RuleView:1.0.0'

二、卷尺功能说明

1. RuleView

基本卷尺控件,主要功能:

  • 手动滑动
  • 惯性滑动
  • 停止后,自动定位到最近的刻度
  • 支持动态修改最小值、最大值、当前值

demo中以体重尺为例,但不限于此

2. MoneySelectRuleView

金额选择尺,除了基本卷尺的功能外,额外的功能有:

  • 可设置“剩余金额”

3. TimeRuleView

时间尺,一天24h内的时间尺,最小刻度是1s

  • 支持惯性滑动
  • 支持缩放时间刻度
  • 支持多个时间段的显示

三、依赖

引用本地lib compile project(path: ':rule_view')

四、使用

4.1 布局

都是最简单的使用,根据需要使用自定义属性即可,详细的自定义属性见五

<com.zjun.widget.RuleView
           ohos:id="$+id:gv_1"
           ohos:width="match_parent"
           ohos:height="70vp"
           ohos:padding="50vp"
           app:zjun_indicatorLineColor = "#ff0000"
   />

   <com.zjun.widget.MoneySelectRuleView
               ohos:id="$+id:msrv_money"
               ohos:width="match_parent"
               ohos:height="match_content"/>

                <com.zjun.widget.TimeRuleView
                           ohos:id="$+id:trv_time"
                           ohos:width="match_parent"
                           ohos:height="match_content"/>

### 4.2 监听回调

主要用来监听当前数值的变化
```java
ruleView.setOnValueChangedListener(new RuleView.OnValueChangedListener() {
   @Override
   public void onValueChanged(float value) {
       tvValue.setText(Float.toString(value));
   }
});
 
// 金额的超额判断,不在自定义View中判断,使用时自行判断,可参考demo
moneySelectRuleView.setOnValueChangedListener(new MoneySelectRuleView.OnValueChangedListener() {
   @Override
   public void onValueChanged(int newValue) {
       tvMoney.setText(Integer.toString(newValue));
   }
});
 
timeRuleView.setOnTimeChangedListener(new TimeRuleView.OnTimeChangedListener() {
   @Override
   public void onTimeChanged(int newTimeValue) {
       tvTime.setText(TimeRuleView.formatTimeHHmmss(newTimeValue));
   }
});

五、属性说明

5.1 RuleView属性

属性名 说明 默认值
zjun_bgColor 背景颜色 #f5f8f5
zjun_gradationColor 刻度颜色 Color.LTGRAY(#CCCCCC)
gv_shortLineWidth 短刻度线的宽度 1dp
gv_shortGradationLen 短刻度长度 16dp
gv_longGradationLen 长刻度长度 gv_shortGradationLen * 2
gv_longLineWidth 长刻度线的宽度 gv_shortLineWidth * 2
zjun_textColor 刻度值字体颜色 Color.BLACK,#000000
zjun_textSize 刻度值字体大小 14sp
zjun_indicatorLineColor 中间指针线的颜色 #48b975
zjun_indicatorLineWidth 中间指针线的宽度 3dp
gv_indicatorLineLen 中间指针线的长度 35dp
gv_minValue 最小值 0f
gv_maxValue 最大值 100f
gv_currentValue 当前值 50f
gv_gradationUnit 刻度间最小单位数值 .1f
gv_numberPerCount 两数值间最小单位的个数 10
gv_gradationGap 最小单位的间距 10dp
gv_gradationNumberGap 数值与最长刻度的间距 8dp

5.2 MoneySelectRuleView属性

属性名 说明 默认值
zjun_bgColor 背景色 #F5F5F5
zjun_gradationColor 刻度颜色 Color.LTGRAY(#CCCCCC)
msrv_gradationHeight 刻度的总高度,刻度基线以上的高度 40dp
msrv_gradationShortLen 短刻度的长度 6dp
msrv_gradationLongLen 长刻度的长度 msrv_gradationShortLen * 2
msrv_gradationShortWidth 短刻度的宽度 1px
msrv_gradationLongWidth 短刻度的长度 msrv_gradationShortWidth
msrv_gradationValueGap 刻度数值与长刻度的间距 8dp
msrv_gradationTextSize 刻度数值文字的大小 12sp
zjun_textColor 刻度数值文字的颜色 Color.GRAY
zjun_indicatorLineColor 中间指针线的颜色 #eb4c1c
msrv_balanceTextSize 余额文字的大小 10sp
msrv_unitGap 最小单位的间距 6dp
msrv_balanceText 余额文字内容 "剩余额度"
msrv_balanceGap 余额文字与刻度基线的间距 4dp
msrv_maxValue 最大金额 50_000
msrv_currentValue 当前金额 0
msrv_balanceValue 剩余金额 0
msrv_valueUnit 每隔最小单位代表的金额值 100
msrv_valuePerCount 刻度数值间的最小单位数 10

5.3 TimeRuleView属性

属性名 说明 默认值
zjun_bgColor 背景颜色 #EEEEEE
zjun_gradationColor 刻度颜色 Color.GRAY
trv_partHeight 时间段的高度 20dp
trv_partColor 时间的颜色 #F58D24
trv_gradationWidth 刻度的宽度 1px
trv_secondLen 秒刻度的长度 3dp
trv_minuteLen 分刻度的长度 5dp
trv_hourLen 时刻度的长度 10dp
trv_gradationTextColor 刻度数值颜色 Color.GRAY
trv_gradationTextSize 刻度数值字体大小 12sp
trv_gradationTextGap 刻度数值与时刻度的间距 2dp
trv_currentTime 当前时间 0(单位:秒,范围∈[0, 24*3600])
trv_indicatorTriangleSideLen 中间指针头部三角形的边长 15dp
zjun_indicatorLineWidth 中间指针的宽度 1dp
zjun_indicatorLineColor 中间指针的颜色 Color.RED

LICENSE Copyright (c) 2018 Ralap

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.

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} 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.

简介

一系列卷尺控件,包含:基本卷尺控件(体重尺,或其它)、金额卷尺控件、时间卷尺控件 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/HarmonyOS-tpc/RulerView.git
git@gitee.com:HarmonyOS-tpc/RulerView.git
HarmonyOS-tpc
RulerView
RulerView
master

搜索帮助