├── .gitignore ├── .idea ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dylanc │ │ └── waveviewdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dylanc │ │ │ └── waveviewdemo │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── dylanc │ └── waveviewdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── gif_wave_view.gif └── screenshot_wave_view.png ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dylanc │ │ └── waveview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dylanc │ │ │ └── waveview │ │ │ └── WaveView.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── dylanc │ └── waveview │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 26 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 55 | 56 | 57 | 58 | 59 | Android API 19 Platform 60 | 61 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## WaveView 2 | ### 简介 3 | 少啰嗦,看东西 4 | ![波浪截图](./img/gif_wave_view.gif) 5 | WaveView 是一个可以高度自定义的波浪控件,能绘制出自己想要的曲线波浪 6 | - 支持设置一个或两个波浪 7 | - 支持分别设置波浪的颜色、振幅、波长、水位线高度、初始偏移量 8 | - 支持分别设置移动一个波长的时间,支持开启和暂停动画 9 | - 支持设置移动方向(左、右) 10 | - 支持设置波浪位置(顶部、底部) 11 | - 支持两种绘制方式(贝塞尔曲线和三角函数曲线) 12 | 13 | ### 用法 14 | #### 1. 在 project 的 build.gradle 添加以下代码 15 | ```gradle 16 | allprojects { 17 | repositories { 18 | ... 19 | maven { url 'https://www.jitpack.io' } 20 | } 21 | } 22 | ``` 23 | #### 2. 在 app 的 build.gradle 添加依赖 24 | ```gradle 25 | dependencies { 26 | implementation 'com.github.CaiShenglang:WaveView:1.0.3' 27 | } 28 | ``` 29 | #### 3. 在 xml 添加 WaveView 30 | ```xml 31 | 51 | ``` 52 | 自定义属性说明 53 | 54 | 自定义属性|类型|作用 55 | ---|:-:|--- 56 | startAnim|boolean|是否开启动画,默认开启 57 | waveCount|integer|波浪数量,默认显示一个 58 | waterLevelHeight|dimension|水位高度,默认是控件高度 - 最大振幅 59 | waveColor|color|第一个波浪的颜色 60 | waveColor2|color|第二个波浪的颜色 61 | waveAmplitude|dimension|第一个波浪的振幅 62 | waveAmplitude2|dimension|第二个波浪的振幅 63 | waveLength|dimension|第一个波浪的波长,默认是控件宽度 64 | waveLength2|dimension|第二个波浪的波长,默认是控件宽度 65 | waveLengthPercent|float|第一个波浪占控件宽度的百分比 66 | waveLengthPercent2|float|第二个波浪占控件宽度的百分比 67 | waveDefOffset|dimension|第一个波浪的初始偏移量 68 | waveDefOffset2|dimension|第二个波浪的初始偏移量 69 | waveDefOffsetPercent|float|第一个波浪默认偏移量占波长的百分比 70 | waveDefOffsetPercent2|float|第二个波浪默认偏移量占第二个波长的百分比 71 | cycleDuration|integer|第一个波浪移动一个周期的时长 72 | cycleDuration2|integer|第二个波浪移动一个周期的时长 73 | moveDirection|left、right|移动方向,默认向右(向左、向右) 74 | waveLocation|top、bottom|波浪位置,默认在底部(顶部、底部) 75 | drawMode|bezier、sin、cos|绘制的模式,默认是贝塞尔曲线绘制(贝塞尔曲线、正弦曲线、余弦曲线) 76 | #### 4. 如果需要动态设置开始或停止动画 77 | ```java 78 | mWaveView = findViewById(R.id.wave_view); 79 | mWaveView.startAnim(); // 开始或继续动画 80 | mWaveView.stopAnim(); // 暂停动画 81 | ``` 82 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 30 5 | buildToolsVersion "30.0.2" 6 | defaultConfig { 7 | applicationId "com.dylanc.waveview" 8 | minSdkVersion 19 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner 'androidx.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 | implementation fileTree(include: ['*.jar'], dir: 'libs') 24 | implementation 'androidx.appcompat:appcompat:1.2.0' 25 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 26 | implementation project(':library') 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/dylanc/waveviewdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.dylanc.waveviewdemo; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented 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.caisl.waveview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/dylanc/waveviewdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dylanc.waveviewdemo; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.view.View; 6 | 7 | import com.dylanc.waveview.WaveView; 8 | 9 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 10 | 11 | private WaveView mWaveView; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | mWaveView = findViewById(R.id.wave_view); 18 | findViewById(R.id.btn_start).setOnClickListener(this); 19 | findViewById(R.id.btn_stop).setOnClickListener(this); 20 | } 21 | 22 | @Override 23 | public void onClick(View view) { 24 | switch (view.getId()) { 25 | case R.id.btn_start: 26 | mWaveView.startAnim(); 27 | break; 28 | case R.id.btn_stop: 29 | mWaveView.stopAnim(); 30 | break; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 30 | 31 |