├── .gitignore ├── README.md ├── appbarlayoutbehavior ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── yuruiyin │ │ └── appbarlayoutbehavior │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── yuruiyin │ │ │ └── appbarlayoutbehavior │ │ │ ├── AppBarLayoutBehavior.java │ │ │ └── LogUtil.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── yuruiyin │ └── appbarlayoutbehavior │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── android.keystore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── yuruiyin │ │ └── sample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── yuruiyin │ │ │ └── sample │ │ │ ├── MainActivity.java │ │ │ ├── MyListFragment.java │ │ │ ├── adapter │ │ │ ├── CustomIndicatorAdapter.java │ │ │ └── RecyclerViewAdapter.java │ │ │ └── divider │ │ │ └── ItemSmallDecoration.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_list.xml │ │ └── item_list.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 │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── yuruiyin │ └── sample │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | # Idea tool config 35 | .idea 36 | *.iml 37 | 38 | traces.txt 39 | 40 | reports/ 41 | 42 | *.DS_Store 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AppBarLayoutBehavior 2 | 解决AppbarLayout滑动问题的behavior 3 | 4 | ## 问题描述 5 | 1) 快速滑动AppBarLayout会出现回弹; 6 | 2) 快速滑动AppBarLayout到折叠状态下,立马下拉会出现抖动现象; 7 | 3) 滑动AppBarLayout过程中,无法像RecyclerView那样通过手指按下停止滚动。 8 | 9 | ## 如何使用 10 | ### gradle 11 | 12 | Step 1. Add the JitPack repository in your root build.gradle at the end of repositories: 13 | ```groovy 14 | allprojects { 15 | repositories { 16 | ... 17 | maven { url 'https://jitpack.io' } 18 | } 19 | } 20 | ``` 21 | Step 2. Add the dependency in your app build.gradle: 22 | ```groovy 23 | dependencies { 24 | // 其中latest-version类似 v1.0.3 25 | implementation 'com.github.yuruiyin:AppbarLayoutBehavior:latest-version' 26 | } 27 | ``` 28 | ### xml 29 | ```xml 30 | 38 | 39 | ...... 40 | 41 | 42 | ``` 43 | 44 | ### 混淆 45 | 若使用support库,则需要保证support库中的代码不被混淆,请在proguard-rules.pro中添加如下配置: 46 | ```proguard 47 | # 保留support下的所有类及内部类 48 | -keep class android.support.**{*;} 49 | -dontwarn android.support.v4.** 50 | # 保留继承support库的类 51 | -keep public class * extends android.support.v4.** 52 | -keep public class * extends android.support.v7.** 53 | -keep public class * extends android.support.annotation.** 54 | ``` 55 | 56 | 若已迁移到androidx,则需要添加如下配置: 57 | ```proguard 58 | -keep class com.google.android.material.** {*;} 59 | -keep class androidx.** {*;} 60 | -keep public class * extends androidx.** 61 | -keep interface androidx.** {*;} 62 | -dontwarn com.google.android.material.** 63 | -dontnote com.google.android.material.** 64 | -dontwarn androidx.** 65 | ``` 66 | 67 | ## 参考 68 | https://blog.csdn.net/vite_s/article/details/78901767 69 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.yuruiyin' 5 | 6 | android { 7 | compileSdkVersion rootProject.ext.compileSdkVersion 8 | 9 | defaultConfig { 10 | minSdkVersion rootProject.ext.minSdkVersion 11 | buildToolsVersion rootProject.ext.buildToolsVersion 12 | targetSdkVersion rootProject.ext.targetSdkVersion 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | 32 | implementation 'androidx.appcompat:appcompat:1.0.2' 33 | implementation 'com.google.android.material:material:1.0.0' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test:runner:1.2.0' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | } 38 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/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 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/src/androidTest/java/com/yuruiyin/appbarlayoutbehavior/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.appbarlayoutbehavior; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.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 | * 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.yuruiyin.appbarlayoutbehavior.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/AppBarLayoutBehavior.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.appbarlayoutbehavior; 2 | 3 | import android.content.Context; 4 | import com.google.android.material.appbar.AppBarLayout; 5 | import androidx.coordinatorlayout.widget.CoordinatorLayout; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | import android.view.View; 9 | import android.widget.OverScroller; 10 | 11 | import java.lang.reflect.Field; 12 | 13 | /** 14 | * 解决appbarLayout若干问题: 15 | * (1)快速滑动appbarLayout会出现回弹 16 | * (2)快速滑动appbarLayout到折叠状态下,立马下滑,会出现抖动的问题 17 | * (3)滑动appbarLayout,无法通过手指按下让其停止滑动 18 | * 19 | * @author yuruiyin 20 | * @version 2018/1/3 21 | */ 22 | public class AppBarLayoutBehavior extends AppBarLayout.Behavior { 23 | 24 | private static final String TAG = "CustomAppbarLayoutBehavior"; 25 | 26 | private static final int TYPE_FLING = 1; 27 | 28 | private boolean isFlinging; 29 | private boolean shouldBlockNestedScroll; 30 | 31 | public AppBarLayoutBehavior(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | } 34 | 35 | @Override 36 | public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent ev) { 37 | LogUtil.d(TAG, "onInterceptTouchEvent:" + child.getTotalScrollRange()); 38 | shouldBlockNestedScroll = false; 39 | if (isFlinging) { 40 | shouldBlockNestedScroll = true; 41 | } 42 | 43 | switch (ev.getActionMasked()) { 44 | case MotionEvent.ACTION_DOWN: 45 | stopAppbarLayoutFling(child); //手指触摸屏幕的时候停止fling事件 46 | break; 47 | } 48 | 49 | return super.onInterceptTouchEvent(parent, child, ev); 50 | } 51 | 52 | /** 53 | * 反射获取私有的flingRunnable 属性,考虑support 28以后变量名修改的问题 54 | * @return Field 55 | */ 56 | private Field getFlingRunnableField() throws NoSuchFieldException { 57 | try { 58 | // support design 27及以下版本 59 | Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass(); 60 | return headerBehaviorType.getDeclaredField("mFlingRunnable"); 61 | } catch (NoSuchFieldException e) { 62 | // 可能是28及以上版本 63 | Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass().getSuperclass(); 64 | return headerBehaviorType.getDeclaredField("flingRunnable"); 65 | } 66 | } 67 | 68 | /** 69 | * 反射获取私有的scroller 属性,考虑support 28以后变量名修改的问题 70 | * @return Field 71 | */ 72 | private Field getScrollerField() throws NoSuchFieldException { 73 | try { 74 | // support design 27及以下版本 75 | Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass(); 76 | return headerBehaviorType.getDeclaredField("mScroller"); 77 | } catch (NoSuchFieldException e) { 78 | // 可能是28及以上版本 79 | Class headerBehaviorType = this.getClass().getSuperclass().getSuperclass().getSuperclass(); 80 | return headerBehaviorType.getDeclaredField("scroller"); 81 | } 82 | } 83 | 84 | /** 85 | * 停止appbarLayout的fling事件 86 | * @param appBarLayout 87 | */ 88 | private void stopAppbarLayoutFling(AppBarLayout appBarLayout) { 89 | //通过反射拿到HeaderBehavior中的flingRunnable变量 90 | try { 91 | Field flingRunnableField = getFlingRunnableField(); 92 | Field scrollerField = getScrollerField(); 93 | flingRunnableField.setAccessible(true); 94 | scrollerField.setAccessible(true); 95 | 96 | Runnable flingRunnable = (Runnable) flingRunnableField.get(this); 97 | OverScroller overScroller = (OverScroller) scrollerField.get(this); 98 | if (flingRunnable != null) { 99 | LogUtil.d(TAG, "存在flingRunnable"); 100 | appBarLayout.removeCallbacks(flingRunnable); 101 | flingRunnableField.set(this, null); 102 | } 103 | if (overScroller != null && !overScroller.isFinished()) { 104 | overScroller.abortAnimation(); 105 | } 106 | } catch (NoSuchFieldException e) { 107 | e.printStackTrace(); 108 | } catch (IllegalAccessException e) { 109 | e.printStackTrace(); 110 | } 111 | } 112 | 113 | @Override 114 | public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child, View directTargetChild, View target, int nestedScrollAxes, int type) { 115 | LogUtil.d(TAG, "onStartNestedScroll"); 116 | stopAppbarLayoutFling(child); 117 | return super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type); 118 | } 119 | 120 | @Override 121 | public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed, int type) { 122 | LogUtil.d(TAG, "onNestedPreScroll:" + child.getTotalScrollRange() + " ,dx:" + dx + " ,dy:" + dy + " ,type:" + type); 123 | 124 | //type返回1时,表示当前target处于非touch的滑动, 125 | //该bug的引起是因为appbar在滑动时,CoordinatorLayout内的实现NestedScrollingChild2接口的滑动子类还未结束其自身的fling 126 | //所以这里监听子类的非touch时的滑动,然后block掉滑动事件传递给AppBarLayout 127 | if (type == TYPE_FLING) { 128 | isFlinging = true; 129 | } 130 | if (!shouldBlockNestedScroll) { 131 | super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); 132 | } 133 | } 134 | 135 | @Override 136 | public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dxConsumed, int dyConsumed, int 137 | dxUnconsumed, int dyUnconsumed, int type) { 138 | LogUtil.d(TAG, "onNestedScroll: target:" + target.getClass() + " ," + child.getTotalScrollRange() + " ,dxConsumed:" 139 | + dxConsumed + " ,dyConsumed:" + dyConsumed + " " + ",type:" + type); 140 | if (!shouldBlockNestedScroll) { 141 | super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type); 142 | } 143 | } 144 | 145 | @Override 146 | public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout abl, View target, int type) { 147 | LogUtil.d(TAG, "onStopNestedScroll"); 148 | super.onStopNestedScroll(coordinatorLayout, abl, target, type); 149 | isFlinging = false; 150 | shouldBlockNestedScroll = false; 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/LogUtil.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.appbarlayoutbehavior; 2 | 3 | import android.os.Build; 4 | import android.util.Log; 5 | 6 | public class LogUtil { 7 | 8 | private static final int VERBOSE = 1; 9 | private static final int DEBUG = 2; 10 | private static final int INFO = 3; 11 | private static final int WARN = 4; 12 | private static final int ERROR = 5; 13 | private static final int NOTHING = 6; 14 | private static final int LEVEL = NOTHING; 15 | 16 | public static void v(String tag, String msg) { 17 | if (LEVEL <= VERBOSE) { 18 | Log.v(tag, msg); 19 | } 20 | } 21 | 22 | public static void d(String tag, String msg) { 23 | if (LEVEL <= DEBUG) { 24 | Log.d(tag, msg); 25 | } 26 | } 27 | 28 | public static void i(String tag, String msg) { 29 | if (LEVEL <= INFO) { 30 | Log.i(tag, msg); 31 | } 32 | } 33 | 34 | public static void w(String tag, String msg) { 35 | if (LEVEL <= WARN) { 36 | Log.w(tag, msg); 37 | } 38 | } 39 | 40 | public static void e(String tag, String msg) { 41 | if (LEVEL <= ERROR) { 42 | Log.e(tag, msg); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AppbarLayoutBehavior 3 | 4 | -------------------------------------------------------------------------------- /appbarlayoutbehavior/src/test/java/com/yuruiyin/appbarlayoutbehavior/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.appbarlayoutbehavior; 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() { 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 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.4.1' 11 | 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' 13 | 14 | 15 | // NOTE: Do not place your application dependencies here; they belong 16 | // in the individual module build.gradle files 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | google() 23 | jcenter() 24 | 25 | maven { url "https://www.jitpack.io" } 26 | } 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | 33 | ext { 34 | compileSdkVersion = 28 35 | buildToolsVersion = '28.0.3' 36 | minSdkVersion = 15 37 | targetSdkVersion = 28 38 | androidSupportVersion = "28.0.0" 39 | } 40 | 41 | //subprojects { 42 | // project.configurations.all { 43 | // resolutionStrategy.eachDependency { details -> 44 | // if (details.requested.group == 'com.android.support' 45 | // && !details.requested.name.contains('multidex') ) { 46 | // details.useVersion androidSupportVersion 47 | // } 48 | // } 49 | // } 50 | //} 51 | 52 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 10 23:58:55 CST 2019 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-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/android.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/android.keystore -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | defaultConfig { 6 | applicationId "com.yuruiyin.sample" 7 | minSdkVersion rootProject.ext.minSdkVersion 8 | buildToolsVersion rootProject.ext.buildToolsVersion 9 | targetSdkVersion rootProject.ext.targetSdkVersion 10 | versionCode 3 11 | versionName "1.0.2" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | 15 | signingConfigs { 16 | debug { 17 | storeFile file('android.keystore') 18 | storePassword "123456" 19 | keyAlias "AppbarLayoutBehavior" 20 | keyPassword "123456" 21 | v1SigningEnabled true 22 | v2SigningEnabled true 23 | } 24 | 25 | release { 26 | storeFile file('android.keystore') 27 | storePassword "123456" 28 | keyAlias "AppbarLayoutBehavior" 29 | keyPassword "123456" 30 | v1SigningEnabled true 31 | v2SigningEnabled true 32 | } 33 | } 34 | 35 | buildTypes { 36 | debug { 37 | signingConfig signingConfigs.debug 38 | ext.enableCrashlytics = false 39 | } 40 | release { 41 | shrinkResources true 42 | zipAlignEnabled true 43 | minifyEnabled true 44 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 45 | signingConfig signingConfigs.release 46 | } 47 | } 48 | 49 | compileOptions { 50 | sourceCompatibility JavaVersion.VERSION_1_8 51 | targetCompatibility JavaVersion.VERSION_1_8 52 | } 53 | } 54 | 55 | dependencies { 56 | implementation fileTree(dir: 'libs', include: ['*.jar']) 57 | implementation 'androidx.appcompat:appcompat:1.0.2' 58 | implementation 'com.google.android.material:material:1.0.0' 59 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 60 | testImplementation 'junit:junit:4.12' 61 | androidTestImplementation 'androidx.test:runner:1.2.0' 62 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 63 | 64 | implementation 'com.github.hackware1993:MagicIndicator:1.5.0' 65 | 66 | implementation 'com.jakewharton:butterknife:10.1.0' 67 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0' 68 | 69 | implementation project(':appbarlayoutbehavior') 70 | 71 | // implementation 'com.github.yuruiyin:AppbarLayoutBehavior:v1.0.2' 72 | 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /sample/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 | 23 | # 保留support下的所有类及内部类 24 | -keep class android.support.**{*;} 25 | -dontwarn android.support.v4.** 26 | # 保留继承support库的类 27 | -keep public class * extends android.support.v4.** 28 | -keep public class * extends android.support.v7.** 29 | -keep public class * extends android.support.annotation.** 30 | 31 | # 若使用androidx 32 | -keep class com.google.android.material.** {*;} 33 | -keep class androidx.** {*;} 34 | -keep public class * extends androidx.** 35 | -keep interface androidx.** {*;} 36 | -dontwarn com.google.android.material.** 37 | -dontnote com.google.android.material.** 38 | -dontwarn androidx.** 39 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/yuruiyin/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.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 | * 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.yuruiyin.appbarlayoutbehavior", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yuruiyin/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample; 2 | 3 | import android.os.Bundle; 4 | import androidx.fragment.app.Fragment; 5 | import androidx.fragment.app.FragmentManager; 6 | import androidx.fragment.app.FragmentPagerAdapter; 7 | import androidx.viewpager.widget.ViewPager; 8 | import androidx.appcompat.app.AppCompatActivity; 9 | 10 | import com.yuruiyin.sample.adapter.CustomIndicatorAdapter; 11 | 12 | import net.lucode.hackware.magicindicator.MagicIndicator; 13 | import net.lucode.hackware.magicindicator.ViewPagerHelper; 14 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | 22 | public class MainActivity extends AppCompatActivity { 23 | 24 | @BindView(R.id.magicIndicator) 25 | MagicIndicator mIndicator; 26 | @BindView(R.id.viewPager) 27 | ViewPager mViewPager; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_main); 33 | 34 | initView(); 35 | } 36 | 37 | private void initView() { 38 | ButterKnife.bind(this); 39 | mViewPager.setAdapter(new MyPageAdapter(getSupportFragmentManager())); 40 | 41 | // 初始化tab 42 | List tabTitles = new ArrayList<>(); 43 | tabTitles.add("tab_1"); 44 | tabTitles.add("tab_2"); 45 | tabTitles.add("tab_3"); 46 | CommonNavigator commonNavigator = new CommonNavigator(this); 47 | commonNavigator.setScrollPivotX(0.65f); 48 | CustomIndicatorAdapter.Data data = new CustomIndicatorAdapter.Data(tabTitles); 49 | commonNavigator.setAdapter(new CustomIndicatorAdapter(mViewPager, data)); 50 | commonNavigator.setAdjustMode(true); 51 | mIndicator.setNavigator(commonNavigator); 52 | ViewPagerHelper.bind(mIndicator, mViewPager); 53 | mIndicator.onPageSelected(mViewPager.getCurrentItem()); 54 | } 55 | 56 | class MyPageAdapter extends FragmentPagerAdapter { 57 | 58 | public MyPageAdapter(FragmentManager fm) { 59 | super(fm); 60 | } 61 | 62 | @Override 63 | public Fragment getItem(int position) { 64 | return MyListFragment.getInstance(position); 65 | } 66 | 67 | @Override 68 | public int getCount() { 69 | return 3; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yuruiyin/sample/MyListFragment.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.NonNull; 5 | import androidx.annotation.Nullable; 6 | import androidx.fragment.app.Fragment; 7 | import androidx.recyclerview.widget.LinearLayoutManager; 8 | import androidx.recyclerview.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.yuruiyin.sample.adapter.RecyclerViewAdapter; 14 | import com.yuruiyin.sample.divider.ItemSmallDecoration; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | 22 | /** 23 | *

Title:

24 | *

Description:

25 | * 26 | * @author yuruiyin 27 | * @version 2018/7/16 28 | */ 29 | public class MyListFragment extends Fragment { 30 | 31 | private static final String PARAM_LIST_DATA = "param_list_data"; 32 | 33 | @BindView(R.id.recyclerView) 34 | RecyclerView mRecyclerView; 35 | 36 | 37 | public static MyListFragment getInstance(int tabPos) { 38 | MyListFragment fragment = new MyListFragment(); 39 | 40 | List listData = new ArrayList<>(); 41 | for (int i = 0; i < 30; i ++) { 42 | listData.add("tab" + (tabPos + 1) + " - item" + (i + 1)); 43 | } 44 | 45 | Bundle bundle = new Bundle(); 46 | bundle.putStringArrayList(PARAM_LIST_DATA, (ArrayList) listData); 47 | fragment.setArguments(bundle); 48 | return fragment; 49 | } 50 | 51 | @Nullable 52 | @Override 53 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 54 | return inflater.inflate(R.layout.fragment_list, container, false); 55 | } 56 | 57 | @Override 58 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 59 | super.onViewCreated(view, savedInstanceState); 60 | initView(); 61 | } 62 | 63 | private void initView() { 64 | ButterKnife.bind(this, getView()); 65 | 66 | // 初始化RecyclerView 67 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 68 | mRecyclerView.setLayoutManager(layoutManager); 69 | List listData = getArguments().getStringArrayList(PARAM_LIST_DATA); 70 | mRecyclerView.setAdapter(new RecyclerViewAdapter(getContext(), listData)); 71 | mRecyclerView.addItemDecoration(new ItemSmallDecoration(getContext())); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yuruiyin/sample/adapter/CustomIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample.adapter; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import androidx.viewpager.widget.ViewPager; 6 | import android.view.animation.AccelerateInterpolator; 7 | import android.view.animation.DecelerateInterpolator; 8 | 9 | 10 | import net.lucode.hackware.magicindicator.buildins.UIUtil; 11 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter; 12 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator; 13 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; 14 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator; 15 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView; 16 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * Created by yuruiyin on 2017/9/22. 22 | */ 23 | 24 | public class CustomIndicatorAdapter extends CommonNavigatorAdapter { 25 | 26 | private ViewPager mViewPager; 27 | 28 | private Data mData; 29 | 30 | /** 31 | * 普通的白底tab需要的data 32 | */ 33 | public static class Data { 34 | public List tabTiles; 35 | public float lineWidthDp; 36 | public float lineHeightDp; 37 | public float lineRoundRadiusDp; 38 | public int lineColor; 39 | public float lineYOffsetDp; 40 | 41 | public float titleTextSizeDp; 42 | public int titleNormalColor; 43 | public int titleSelectedColor; 44 | 45 | public Data(List tabTiles) { 46 | // 设置默认值 47 | this.tabTiles = tabTiles; 48 | this.lineWidthDp = -1; //说明下划线长度自适应 49 | this.lineHeightDp = 2.5f; 50 | this.lineRoundRadiusDp = 0; 51 | this.lineColor = Color.parseColor("#3F51B5"); 52 | this.lineYOffsetDp = 0; 53 | 54 | this.titleTextSizeDp = 14; 55 | this.titleNormalColor = Color.parseColor("#aaaaaa"); 56 | this.titleSelectedColor = Color.parseColor("#3F51B5"); 57 | } 58 | } 59 | 60 | public CustomIndicatorAdapter(ViewPager viewPager, Data data) { 61 | mViewPager = viewPager; 62 | mData = data; 63 | } 64 | 65 | @Override 66 | public int getCount() { 67 | return mData.tabTiles == null ? 0 : mData.tabTiles.size(); 68 | } 69 | 70 | @Override 71 | public IPagerTitleView getTitleView(Context context, int position) { 72 | BadgePagerTitleView badgePagerTitleView = new BadgePagerTitleView(context); 73 | 74 | SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context); 75 | simplePagerTitleView.setTextSize(mData.titleTextSizeDp); 76 | simplePagerTitleView.setText(getTitle(position)); 77 | simplePagerTitleView.setNormalColor(mData.titleNormalColor); 78 | simplePagerTitleView.setSelectedColor(mData.titleSelectedColor); 79 | simplePagerTitleView.setOnClickListener(v -> mViewPager.setCurrentItem(position)); 80 | // simplePagerTitleView.setPadding(UIUtil.dip2px(context, 20), 0, UIUtil.dip2px(context, 20), 0); 81 | badgePagerTitleView.setInnerPagerTitleView(simplePagerTitleView); 82 | 83 | return badgePagerTitleView; 84 | } 85 | 86 | @Override 87 | public IPagerIndicator getIndicator(Context context) { 88 | LinePagerIndicator indicator = new LinePagerIndicator(context); 89 | indicator.setLineHeight(UIUtil.dip2px(context, mData.lineHeightDp)); 90 | if(mData.lineWidthDp != -1) { 91 | indicator.setMode(LinePagerIndicator.MODE_EXACTLY); 92 | indicator.setLineWidth(UIUtil.dip2px(context, mData.lineWidthDp)); 93 | } 94 | indicator.setRoundRadius(UIUtil.dip2px(context, mData.lineRoundRadiusDp)); 95 | indicator.setStartInterpolator(new AccelerateInterpolator()); 96 | indicator.setEndInterpolator(new DecelerateInterpolator(2.0f)); 97 | indicator.setColors(mData.lineColor); 98 | indicator.setYOffset(UIUtil.dip2px(context, mData.lineYOffsetDp)); 99 | return indicator; 100 | } 101 | 102 | @Override 103 | public float getTitleWeight(Context context, int index) { 104 | return 1.0f; 105 | } 106 | 107 | public String getTitle(int position) { 108 | return mData.tabTiles.get(position); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yuruiyin/sample/adapter/RecyclerViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.annotation.NonNull; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.yuruiyin.sample.R; 12 | 13 | import java.util.List; 14 | 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | 18 | /** 19 | *

Title:

20 | *

Description:

21 | * 22 | * @author yuruiyin 23 | * @version 2018/7/16 24 | */ 25 | public class RecyclerViewAdapter extends RecyclerView.Adapter { 26 | 27 | private Context mContext; 28 | private List mListData; 29 | private LayoutInflater mInflater; 30 | 31 | public RecyclerViewAdapter(Context context, List listData) { 32 | mContext = context; 33 | mListData = listData; 34 | mInflater = LayoutInflater.from(mContext); 35 | } 36 | 37 | @NonNull 38 | @Override 39 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 40 | View view = mInflater.inflate(R.layout.item_list, parent, false); 41 | return new ViewHolder(view); 42 | } 43 | 44 | @Override 45 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) { 46 | String content = mListData.get(position); 47 | holder.mTvContent.setText(content); 48 | } 49 | 50 | @Override 51 | public int getItemCount() { 52 | return mListData == null ? 0 : mListData.size(); 53 | } 54 | 55 | class ViewHolder extends RecyclerView.ViewHolder { 56 | 57 | @BindView(R.id.content) 58 | TextView mTvContent; 59 | 60 | public ViewHolder(View itemView) { 61 | super(itemView); 62 | ButterKnife.bind(this, itemView); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yuruiyin/sample/divider/ItemSmallDecoration.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample.divider; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Paint; 6 | import android.graphics.Rect; 7 | import androidx.core.content.ContextCompat; 8 | import androidx.recyclerview.widget.RecyclerView; 9 | import android.view.View; 10 | 11 | import com.yuruiyin.sample.R; 12 | 13 | /** 14 | *

Title:

15 | *

Description:

16 | * 17 | * @author yuruiyin 18 | * @version 2017/7/4 19 | */ 20 | 21 | public class ItemSmallDecoration extends RecyclerView.ItemDecoration { 22 | 23 | private int dividerHeight; 24 | private Paint dividerPaint; 25 | 26 | public ItemSmallDecoration(Context context) { 27 | this(context, (int) context.getResources().getDimension(R.dimen.common_divider_small_height)); 28 | } 29 | 30 | public ItemSmallDecoration(Context context, int dividerHeight) { 31 | this.dividerHeight = dividerHeight; 32 | dividerPaint = new Paint(); 33 | dividerPaint.setColor(ContextCompat.getColor(context, R.color.divider)); 34 | } 35 | 36 | @Override 37 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 38 | super.getItemOffsets(outRect, view, parent, state); 39 | outRect.bottom = dividerHeight; 40 | } 41 | 42 | @Override 43 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 44 | int childCount = parent.getChildCount() - 1; 45 | int left = parent.getPaddingLeft(); 46 | int right = parent.getWidth() - parent.getPaddingRight(); 47 | 48 | for (int i = 0; i < childCount; i++) { 49 | View view = parent.getChildAt(i); 50 | float top = view.getBottom(); 51 | float bottom = view.getBottom() + dividerHeight; 52 | c.drawRect(left, top, right, bottom, dividerPaint); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 9 | 15 | 16 | 23 | 27 | 31 | 32 | 33 | 34 | 41 | 42 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 13 | 19 | 25 | 31 | 37 | 43 | 49 | 55 | 61 | 67 | 73 | 79 | 85 | 91 | 97 | 103 | 109 | 115 | 121 | 127 | 133 | 139 | 145 | 151 | 157 | 163 | 169 | 175 | 181 | 187 | 193 | 199 | 205 | 206 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 24 | 25 | 34 | 35 | 36 | 37 | 38 | 46 | 47 | 52 | 53 | 54 | 55 | 62 | 63 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_list.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_list.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuruiyin/AppbarLayoutBehavior/ea3d99a85b918392731c8e5667719941d9357857/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #fff 8 | 9 | #00ff00 10 | 11 | #f3f3f3 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 40dp 5 | 6 | 7 | 44dp 8 | 9 | 10 | 15dp 11 | 12 | 16dp 13 | 14 | 1dp 15 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AppbarLayoutBehavior 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/test/java/com/yuruiyin/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.yuruiyin.sample; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':appbarlayoutbehavior' 2 | --------------------------------------------------------------------------------