├── .gitattributes ├── .gitignore ├── .gradle └── 2.14.1 │ ├── taskArtifacts │ ├── cache.properties │ ├── cache.properties.lock │ ├── fileHashes.bin │ ├── fileSnapshots.bin │ ├── fileSnapshotsToTreeSnapshotsIndex.bin │ └── taskArtifacts.bin │ └── tasks │ └── _app_compileDebugJavaWithJavac │ ├── localClassSetAnalysis │ ├── localClassSetAnalysis.bin │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ ├── localJarClasspathSnapshot.bin │ └── localJarClasspathSnapshot.lock ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── animated_vector_drawable_24_2_1.xml │ ├── appcompat_v7_24_2_1.xml │ ├── espresso_core_2_2_2.xml │ ├── espresso_idling_resource_2_2_2.xml │ ├── exposed_instrumentation_api_publish_0_5.xml │ ├── hamcrest_core_1_3.xml │ ├── hamcrest_integration_1_3.xml │ ├── hamcrest_library_1_3.xml │ ├── javawriter_2_1_1.xml │ ├── javax_annotation_api_1_2.xml │ ├── javax_inject_1.xml │ ├── jsr305_2_0_1.xml │ ├── junit_4_12.xml │ ├── rules_0_5.xml │ ├── runner_0_5.xml │ ├── support_annotations_24_2_1.xml │ ├── support_compat_24_2_1.xml │ ├── support_core_ui_24_2_1.xml │ ├── support_core_utils_24_2_1.xml │ ├── support_fragment_24_2_1.xml │ ├── support_media_compat_24_2_1.xml │ ├── support_v4_24_2_1.xml │ └── support_vector_drawable_24_2_1.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── workspace.xml ├── 7c0d4213-1242-496b-9898-0d04d14f3097.gif ├── README.md ├── RuleView2.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zkk │ │ └── ruleview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zkk │ │ │ └── activity │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-xhdpi │ │ ├── register_info_line.png │ │ ├── user_info_ruler_birthday.png │ │ ├── user_info_ruler_height.png │ │ ├── user_info_ruler_weight.png │ │ ├── user_sex_switch_boy.png │ │ └── user_sex_switch_girl.png │ │ ├── drawable │ │ └── user_sex_selector.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── activity_test.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── zkk │ └── ruleview │ └── ExampleUnitTest.java ├── build.gradle ├── build └── intermediates │ └── dex-cache │ └── cache.xml ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── myruleview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zkk │ │ └── view │ │ └── rulerview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zkk │ │ │ └── view │ │ │ └── rulerview │ │ │ └── RulerView.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── zkk │ └── view │ └── rulerview │ └── ExampleUnitTest.java └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # ========================= 15 | # Operating System Files 16 | # ========================= 17 | 18 | # OSX 19 | # ========================= 20 | 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Thumbnails 26 | ._* 27 | 28 | # Files that might appear in the root of a volume 29 | .DocumentRevisions-V100 30 | .fseventsd 31 | .Spotlight-V100 32 | .TemporaryItems 33 | .Trashes 34 | .VolumeIcon.icns 35 | 36 | # Directories potentially created on remote AFP share 37 | .AppleDB 38 | .AppleDesktop 39 | Network Trash Folder 40 | Temporary Items 41 | .apdisk 42 | 43 | # Windows 44 | # ========================= 45 | 46 | # Windows image file caches 47 | Thumbs.db 48 | ehthumbs.db 49 | 50 | # Folder config file 51 | Desktop.ini 52 | 53 | # Recycle Bin used on file shares 54 | $RECYCLE.BIN/ 55 | 56 | # Windows Installer files 57 | *.cab 58 | *.msi 59 | *.msm 60 | *.msp 61 | 62 | # Windows shortcuts 63 | *.lnk 64 | -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/cache.properties: -------------------------------------------------------------------------------- 1 | #Tue Dec 27 20:53:34 CST 2016 2 | -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/cache.properties.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/taskArtifacts/cache.properties.lock -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/taskArtifacts/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/fileSnapshots.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/taskArtifacts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/animated_vector_drawable_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/espresso_core_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/espresso_idling_resource_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/exposed_instrumentation_api_publish_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_integration_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_library_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/javawriter_2_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/javax_annotation_api_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/javax_inject_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/jsr305_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/rules_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/runner_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_compat_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_ui_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_utils_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/support_fragment_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_media_compat_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/support_vector_drawable_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /7c0d4213-1242-496b-9898-0d04d14f3097.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/7c0d4213-1242-496b-9898-0d04d14f3097.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RuleView 2 | 尺子刻度 -- 自定义view 3 | ###自定义view学习(第一章) 4 | 5 | *** 6 | ##### 1、自定义刻度尺控件 7 | 8 | 在我们想要获取用户的身高体重等信息时,直接让他们输入显然不够友好偶然看到一款App用了类似刻度尺的界面让用户选择,觉得很赞。所有决定实现下。 9 | 实现的最终效果如下图所示: 10 | 11 | ![7c0d4213-1242-496b-9898-0d04d14f3097.gif](https://github.com/panacena/RuleView/blob/master/7c0d4213-1242-496b-9898-0d04d14f3097.gif) 12 | 13 | *** 14 | #####2、使用方式 15 | 16 | ######2.1 在gradle添加依赖 17 | ``` 18 | compile 'com.zkk.view:ZkkRulerView:1.0.0' 19 | ``` 20 | ######2.2 在xml中设置 21 | 22 | ``` 23 | 41 | ``` 42 | ######2.3 在activity中只需调用一个方法和一个数值的回调 43 | ``` 44 | ruler_height=(RulerView)findViewById(R.id.ruler_height); 45 | ruler_weight.setOnValueChangeListener(new RulerView.OnValueChangeListener() { 46 | @Override 47 | public void onValueChange(float value) { 48 | tv_register_info_weight_value.setText(value+""); 49 | } 50 | }); 51 | 52 | /** 53 | * 54 | * @param selectorValue 未选择时 默认的值 滑动后表示当前中间指针正在指着的值 55 | * @param minValue 最大数值 56 | * @param maxValue 最小的数值 57 | * @param per 最小单位 如 1:表示 每2条刻度差为1. 0.1:表示 每2条刻度差为0.1 在demo中 身高mPerValue为1 体重mPerValue 为0.1 58 | */ 59 | ruler_weight.setValue(165, 80, 250, 1); 60 | ``` 61 | 62 | *** 63 | ##### 3、实现讲解 64 | 65 | 博客地址: 66 | [http://www.jianshu.com/p/5d1fa50298b3](http://www.jianshu.com/p/5d1fa50298b3) 67 | 68 | 69 | -------------------------------------------------------------------------------- /RuleView2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.3" 6 | defaultConfig { 7 | applicationId "com.zkk.ruleview" 8 | minSdkVersion 15 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24+' 28 | testCompile 'junit:junit:4.12' 29 | compile 'com.zkk.view:ZkkRulerView:1.0.0' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zkk/ruleview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.zkk.ruleview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.zkk.ruleview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/zkk/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zkk.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | 7 | import com.zkk.rulerview.R; 8 | import com.zkk.view.rulerview.RulerView; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | private RulerView ruler_height; //身高的view 13 | private RulerView ruler_weight ; //体重的view 14 | private TextView tv_register_info_height_value,tv_register_info_weight_value; 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | ruler_height=(RulerView)findViewById(R.id.ruler_height); 21 | ruler_weight=(RulerView)findViewById(R.id.ruler_weight); 22 | 23 | tv_register_info_height_value=(TextView) findViewById(R.id.tv_register_info_height_value); 24 | tv_register_info_weight_value=(TextView) findViewById(R.id.tv_register_info_weight_value); 25 | 26 | 27 | ruler_height.setOnValueChangeListener(new RulerView.OnValueChangeListener() { 28 | @Override 29 | public void onValueChange(float value) { 30 | tv_register_info_height_value.setText(value+""); 31 | } 32 | }); 33 | 34 | 35 | ruler_weight.setOnValueChangeListener(new RulerView.OnValueChangeListener() { 36 | @Override 37 | public void onValueChange(float value) { 38 | tv_register_info_weight_value.setText(value+""); 39 | } 40 | }); 41 | 42 | ruler_height.setValue(165, 80, 250, 1); 43 | 44 | ruler_weight.setValue(55, 20, 200, 0.1f); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/register_info_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/drawable-xhdpi/register_info_line.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/user_info_ruler_birthday.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/drawable-xhdpi/user_info_ruler_birthday.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/user_info_ruler_height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/drawable-xhdpi/user_info_ruler_height.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/user_info_ruler_weight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/drawable-xhdpi/user_info_ruler_weight.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/user_sex_switch_boy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/drawable-xhdpi/user_sex_switch_boy.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/user_sex_switch_girl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/drawable-xhdpi/user_sex_switch_girl.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/user_sex_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | 14 | 23 | 24 | --> 32 | 38 | 39 | 47 | 48 | 58 | 59 | 62 | 63 | 81 | 82 | 89 | 90 | 91 | 97 | 98 | 99 | 107 | 108 | 118 | 119 | 123 | 124 | 133 | 134 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 23 | 24 | 29 | 30 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cStor-cDeep/RuleView/1f5dc2b1c335c49aae76c722ed433f1f43bd20d1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #D3D3D3 7 | #000000 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RulerView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/zkk/ruleview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zkk.ruleview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.0' 9 | classpath 'com.novoda:bintray-release:0.3.4' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /build/intermediates/dex-cache/cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 20 | 21 | 22 | 29 | 30 | 31 | 38 | 39 | 40 | 47 | 48 | 49 | 56 | 57 | 58 | 65 | 66 | 67 | 74 | 75 | 76 | 83 | 84 | 85 | 92 | 93 | 94 | 101 | 102 | 103 | 110 | 111 | 112 | 119 | 120 | 121 | 128 | 129 | 130 | 137 | 138 | 139 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | #Tue Dec 27 20:53:25 CST 2016 11 | ndk.dir=C\:\\Users\\Administrator\\AppData\\Local\\Android\\Sdk\\ndk-bundle 12 | sdk.dir=C\:\\Users\\Administrator\\AppData\\Local\\Android\\Sdk 13 | -------------------------------------------------------------------------------- /myruleview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /myruleview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "24.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | publish { 26 | userOrg = 'panacena' //Bintray注册的用户名 27 | /* 28 | * compile 'com.android.support:appcompat-v7:24.0.0' 29 | */ 30 | groupId = 'com.zkk.view' //compile引用时的groupId 形如 com.android.support 31 | artifactId = 'ZkkRulerView' //compile引用时的项目名 形如 appcompat-v7 32 | publishVersion = '1.0.0' //compile引用时的版本号 形如 24.0.0 33 | desc = 'Android自定义标尺控件(选择身高、体重等)' //描述 34 | website = 'https://github.com/panacena/RuleView' //可以填写 git地址 35 | } 36 | tasks.withType(Javadoc) { 37 | options{ encoding "UTF-8" 38 | charSet 'UTF-8' 39 | links "http://docs.oracle.com/javase/7/docs/api" 40 | } 41 | } 42 | 43 | dependencies { 44 | compile fileTree(dir: 'libs', include: ['*.jar']) 45 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 46 | exclude group: 'com.android.support', module: 'support-annotations' 47 | }) 48 | compile 'com.android.support:appcompat-v7:24+' 49 | testCompile 'junit:junit:4.12' 50 | } 51 | -------------------------------------------------------------------------------- /myruleview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /myruleview/src/androidTest/java/com/zkk/view/rulerview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.zkk.view.rulerview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.zkk.view.rulerview.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /myruleview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /myruleview/src/main/java/com/zkk/view/rulerview/RulerView.java: -------------------------------------------------------------------------------- 1 | package com.zkk.view.rulerview; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.util.AttributeSet; 9 | import android.util.Log; 10 | import android.view.MotionEvent; 11 | import android.view.VelocityTracker; 12 | import android.view.View; 13 | import android.view.ViewConfiguration; 14 | import android.widget.Scroller; 15 | 16 | 17 | public class RulerView extends View { 18 | 19 | private int mMinVelocity; 20 | private Scroller mScroller; //Scroller是一个专门用于处理滚动效果的工具类 用mScroller记录/计算View滚动的位置,再重写View的computeScroll(),完成实际的滚动 21 | private VelocityTracker mVelocityTracker; //主要用跟踪触摸屏事件(flinging事件和其他gestures手势事件)的速率。 22 | private int mWidth; 23 | private int mHeight; 24 | 25 | private float mSelectorValue = 50.0f; // 未选择时 默认的值 滑动后表示当前中间指针正在指着的值 26 | private float mMaxValue = 200; // 最大数值 27 | private float mMinValue = 100.0f; //最小的数值 28 | private float mPerValue = 1; //最小单位 如 1:表示 每2条刻度差为1. 0.1:表示 每2条刻度差为0.1 29 | // 在demo中 身高mPerValue为1 体重mPerValue 为0.1 30 | 31 | private float mLineSpaceWidth = 5; // 尺子刻度2条线之间的距离 32 | private float mLineWidth = 4; // 尺子刻度的宽度 33 | private float mLineMaxHeight = 420; // 尺子刻度分为3中不同的高度。 mLineMaxHeight表示最长的那根(也就是 10的倍数时的高度) 34 | private float mLineMidHeight = 30; // mLineMidHeight 表示中间的高度(也就是 5 15 25 等时的高度) 35 | private float mLineMinHeight = 17; // mLineMinHeight 表示最短的那个高度(也就是 1 2 3 4 等时的高度) 36 | 37 | private float mTextMarginTop = 10; //o 38 | private float mTextSize =30; //尺子刻度下方数字 textsize 39 | 40 | private boolean mAlphaEnable = false; // 尺子 最左边 最后边是否需要透明 (透明效果更好点) 41 | 42 | private float mTextHeight; //尺子刻度下方数字 的高度 43 | 44 | private Paint mTextPaint; // 尺子刻度下方数字( 也就是每隔10个出现的数值) paint 45 | private Paint mLinePaint; // 尺子刻度 paint 46 | 47 | private int mTotalLine; //共有多少条 刻度 48 | private int mMaxOffset; //所有刻度 共有多长 49 | private float mOffset; // 默认状态下,mSelectorValue所在的位置 位于尺子总刻度的位置 50 | private int mLastX, mMove; 51 | private OnValueChangeListener mListener; // 滑动后数值回调 52 | 53 | private int mLineColor = Color.GRAY; //刻度的颜色 54 | private int mTextColor=Color.BLACK; //文字的颜色 55 | 56 | 57 | public RulerView(Context context) { 58 | this(context, null); 59 | 60 | } 61 | 62 | public RulerView(Context context, AttributeSet attrs) { 63 | this(context, attrs, 0); 64 | } 65 | 66 | public RulerView(Context context, AttributeSet attrs, int defStyleAttr) { 67 | super(context, attrs, defStyleAttr); 68 | init(context,attrs); 69 | } 70 | 71 | protected void init(Context context, AttributeSet attrs) { 72 | Log.d("zkk---","init"); 73 | mScroller = new Scroller(context); 74 | 75 | 76 | this.mLineSpaceWidth = myfloat(25.0F); 77 | this.mLineWidth = myfloat(2.0F); 78 | this.mLineMaxHeight = myfloat(100.0F); 79 | this.mLineMidHeight = myfloat(60.0F); 80 | this.mLineMinHeight = myfloat(40.0F); 81 | this.mTextHeight = myfloat(40.0F); 82 | 83 | 84 | final TypedArray typedArray = context.obtainStyledAttributes(attrs, 85 | R.styleable.RulerView); 86 | 87 | mAlphaEnable = typedArray.getBoolean(R.styleable.RulerView_alphaEnable, mAlphaEnable); 88 | 89 | mLineSpaceWidth = typedArray.getDimension(R.styleable.RulerView_lineSpaceWidth, mLineSpaceWidth); 90 | mLineWidth = typedArray.getDimension(R.styleable.RulerView_lineWidth, mLineWidth); 91 | mLineMaxHeight = typedArray.getDimension(R.styleable.RulerView_lineMaxHeight, mLineMaxHeight); 92 | mLineMidHeight = typedArray.getDimension(R.styleable.RulerView_lineMidHeight, mLineMidHeight); 93 | mLineMinHeight = typedArray.getDimension(R.styleable.RulerView_lineMinHeight, mLineMinHeight); 94 | mLineColor = typedArray.getColor(R.styleable.RulerView_lineColor, mLineColor); 95 | 96 | mTextSize = typedArray.getDimension(R.styleable.RulerView_textSize, mTextSize); 97 | mTextColor = typedArray.getColor(R.styleable.RulerView_textColor, mTextColor); 98 | mTextMarginTop = typedArray.getDimension(R.styleable.RulerView_textMarginTop, mTextMarginTop); 99 | 100 | mSelectorValue = typedArray.getFloat(R.styleable.RulerView_selectorValue, 0.0f); 101 | mMinValue = typedArray.getFloat(R.styleable.RulerView_minValue, 0.0f); 102 | mMaxValue = typedArray.getFloat(R.styleable.RulerView_maxValue, 100.0f); 103 | mPerValue = typedArray.getFloat(R.styleable.RulerView_perValue, 0.1f); 104 | 105 | 106 | 107 | mMinVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity(); 108 | 109 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 110 | mTextPaint.setTextSize(mTextSize); 111 | mTextPaint.setColor(mTextColor); 112 | mTextHeight = getFontHeight(mTextPaint); 113 | 114 | mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 115 | mLinePaint.setStrokeWidth(mLineWidth); 116 | mLinePaint.setColor(mLineColor); 117 | 118 | 119 | 120 | // setValue(1990, 1940, 2016, 1); 121 | 122 | } 123 | 124 | 125 | public static int myfloat(float paramFloat){ 126 | return (int)(0.5F + paramFloat * 1.0f); 127 | } 128 | 129 | private float getFontHeight(Paint paint) { 130 | Paint.FontMetrics fm = paint.getFontMetrics(); 131 | return fm.descent - fm.ascent; 132 | } 133 | 134 | 135 | /** 136 | * 137 | * @param selectorValue 未选择时 默认的值 滑动后表示当前中间指针正在指着的值 138 | * @param minValue 最大数值 139 | * @param maxValue 最小的数值 140 | * @param per 最小单位 如 1:表示 每2条刻度差为1. 0.1:表示 每2条刻度差为0.1 在demo中 身高mPerValue为1 体重mPerValue 为0.1 141 | */ 142 | public void setValue(float selectorValue, float minValue, float maxValue, float per) { 143 | this.mSelectorValue = selectorValue; 144 | this.mMaxValue = maxValue; 145 | this.mMinValue = minValue; 146 | this.mPerValue = (int) (per * 10.0f); 147 | this.mTotalLine = ((int) ((mMaxValue * 10 - mMinValue * 10) / mPerValue)) + 1; 148 | 149 | 150 | mMaxOffset = (int) (-(mTotalLine - 1) * mLineSpaceWidth); 151 | mOffset = (mMinValue - mSelectorValue) / mPerValue * mLineSpaceWidth * 10; 152 | Log.d("zkk===","mOffset-- "+mOffset +" =====mMaxOffset "+mMaxOffset 153 | +" mTotalLine " +mTotalLine); 154 | invalidate(); 155 | setVisibility(VISIBLE); 156 | } 157 | 158 | public void setOnValueChangeListener(OnValueChangeListener listener) { 159 | mListener = listener; 160 | } 161 | 162 | @Override 163 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 164 | 165 | super.onSizeChanged(w, h, oldw, oldh); 166 | if (w > 0 && h > 0) { 167 | mWidth = w; 168 | mHeight = h; 169 | } 170 | } 171 | 172 | @Override 173 | protected void onDraw(Canvas canvas) { 174 | super.onDraw(canvas); 175 | 176 | float left, height; 177 | String value; 178 | int alpha = 0; 179 | float scale; 180 | int srcPointX = mWidth / 2; 181 | for (int i = 0; i < mTotalLine; i++) { 182 | left = srcPointX + mOffset + i * mLineSpaceWidth; 183 | 184 | if (left < 0 || left > mWidth) { 185 | continue; // 先画默认值在正中间,左右各一半的view。 多余部分暂时不画(也就是从默认值在中间,画旁边左右的刻度线) 186 | } 187 | 188 | if (i % 10 == 0) { 189 | height = mLineMaxHeight; 190 | } else if (i % 5 == 0) { 191 | height = mLineMidHeight; 192 | } else { 193 | height = mLineMinHeight; 194 | } 195 | if (mAlphaEnable) { 196 | scale = 1 - Math.abs(left - srcPointX) / srcPointX; 197 | alpha = (int) (255 * scale * scale); 198 | 199 | mLinePaint.setAlpha(alpha); 200 | } 201 | canvas.drawLine(left, 0, left, height, mLinePaint); 202 | 203 | if (i % 10 == 0) { 204 | value = String.valueOf((int) (mMinValue + i * mPerValue / 10)); 205 | if (mAlphaEnable) { 206 | mTextPaint.setAlpha(alpha); 207 | } 208 | canvas.drawText(value, left - mTextPaint.measureText(value) / 2, 209 | height + mTextMarginTop + mTextHeight, mTextPaint); // 在为整数时,画 数值 210 | } 211 | 212 | } 213 | } 214 | 215 | @Override 216 | public boolean onTouchEvent(MotionEvent event) { 217 | Log.d("zkk---","onTouchEvent-"); 218 | 219 | int action = event.getAction(); 220 | int xPosition = (int) event.getX(); 221 | 222 | if (mVelocityTracker == null) { 223 | mVelocityTracker = VelocityTracker.obtain(); 224 | } 225 | mVelocityTracker.addMovement(event); 226 | 227 | switch (action) { 228 | case MotionEvent.ACTION_DOWN: 229 | mScroller.forceFinished(true); 230 | mLastX = xPosition; 231 | mMove = 0; 232 | break; 233 | case MotionEvent.ACTION_MOVE: 234 | mMove = (mLastX - xPosition); 235 | changeMoveAndValue(); 236 | break; 237 | case MotionEvent.ACTION_UP: 238 | case MotionEvent.ACTION_CANCEL: 239 | countMoveEnd(); 240 | countVelocityTracker(); 241 | return false; 242 | default: 243 | break; 244 | } 245 | 246 | mLastX = xPosition; 247 | return true; 248 | } 249 | 250 | private void countVelocityTracker() { 251 | Log.d("zkk---","countVelocityTracker-"); 252 | mVelocityTracker.computeCurrentVelocity(1000); //初始化速率的单位 253 | float xVelocity = mVelocityTracker.getXVelocity(); //当前的速度 254 | if (Math.abs(xVelocity) > mMinVelocity) { 255 | mScroller.fling(0, 0, (int) xVelocity, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); 256 | } 257 | } 258 | 259 | 260 | /** 261 | * 滑动结束后,若是指针在2条刻度之间时,改变mOffset 让指针正好在刻度上。 262 | */ 263 | private void countMoveEnd() { 264 | 265 | mOffset -= mMove; 266 | if (mOffset <= mMaxOffset) { 267 | mOffset = mMaxOffset; 268 | } else if (mOffset >= 0) { 269 | mOffset = 0; 270 | } 271 | 272 | mLastX = 0; 273 | mMove = 0; 274 | 275 | mSelectorValue = mMinValue + Math.round(Math.abs(mOffset) * 1.0f / mLineSpaceWidth) * mPerValue / 10.0f; 276 | mOffset = (mMinValue - mSelectorValue) * 10.0f / mPerValue * mLineSpaceWidth; 277 | 278 | 279 | 280 | notifyValueChange(); 281 | postInvalidate(); 282 | } 283 | 284 | 285 | /** 286 | * 滑动后的操作 287 | */ 288 | private void changeMoveAndValue() { 289 | mOffset -= mMove; 290 | 291 | if (mOffset <= mMaxOffset) { 292 | mOffset = mMaxOffset; 293 | mMove = 0; 294 | mScroller.forceFinished(true); 295 | } else if (mOffset >= 0) { 296 | mOffset = 0; 297 | mMove = 0; 298 | mScroller.forceFinished(true); 299 | } 300 | mSelectorValue = mMinValue + Math.round(Math.abs(mOffset) * 1.0f / mLineSpaceWidth) * mPerValue / 10.0f; 301 | 302 | 303 | notifyValueChange(); 304 | postInvalidate(); 305 | } 306 | 307 | private void notifyValueChange() { 308 | if (null != mListener) { 309 | mListener.onValueChange(mSelectorValue); 310 | } 311 | } 312 | 313 | 314 | /** 315 | * 滑动后的回调 316 | */ 317 | public interface OnValueChangeListener { 318 | void onValueChange(float value); 319 | } 320 | 321 | @Override 322 | public void computeScroll() { 323 | Log.d("zkk---","computeScroll-"); 324 | super.computeScroll(); 325 | if (mScroller.computeScrollOffset()) { //mScroller.computeScrollOffset()返回 true表示滑动还没有结束 326 | if (mScroller.getCurrX() == mScroller.getFinalX()) { 327 | countMoveEnd(); 328 | } else { 329 | int xPosition = mScroller.getCurrX(); 330 | mMove = (mLastX - xPosition); 331 | changeMoveAndValue(); 332 | mLastX = xPosition; 333 | } 334 | } 335 | } 336 | } 337 | -------------------------------------------------------------------------------- /myruleview/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /myruleview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MyRuleView 3 | 4 | -------------------------------------------------------------------------------- /myruleview/src/test/java/com/zkk/view/rulerview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zkk.view.rulerview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------