AppbarLayoutBehavior
Introduction: 解决 AppbarLayout 滑动问题的 behavior
Tags:
解决 AppbarLayout 滑动问题的 behavior
问题描述
1) 快速滑动 AppBarLayout 会出现回弹; 2) 快速滑动 AppBarLayout 到折叠状态下,立马下拉会出现抖动现象; 3) 滑动 AppBarLayout 过程中,无法像 RecyclerView 那样通过手指按下停止滚动。
如何使用
gradle
Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency in your app build.gradle:
dependencies {
// 其中 latest-version 类似 v1.0.3
implementation 'com.github.yuruiyin:AppbarLayoutBehavior:latest-version'
}
xml
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:fitsSystemWindows="false"
app:layout_behavior="com.yuruiyin.appbarlayoutbehavior.AppBarLayoutBehavior"
>
......
</android.support.design.widget.AppBarLayout>
混淆
若使用 support 库,则需要保证 support 库中的代码不被混淆,请在 proguard-rules.pro 中添加如下配置:
# 保留 support 下的所有类及内部类
-keep class android.support.**{*;}
-dontwarn android.support.v4.**
# 保留继承 support 库的类
-keep public class * extends android.support.v4.**
-keep public class * extends android.support.v7.**
-keep public class * extends android.support.annotation.**
若已迁移到 androidx,则需要添加如下配置:
-keep class com.google.android.material.** {*;}
-keep class androidx.** {*;}
-keep public class * extends androidx.**
-keep interface androidx.** {*;}
-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**
-dontwarn androidx.**