preface

First of all, I believe that most Android application layer developers have used the AppBarLayout layout. right The classic CoordinatorLayout + AppBarLayout + CollapsingToolbarLayout + TabLayout + NestedScrollView is familiar to CollapsingToolbarLayout + TabLayout + NestedScrollView www.jianshu.com/p/06c0ae8d9,…). . Perhaps everyone will agree that the above layout combination is very useful in real application scenarios, however, AppBaryLayout still has some sliding problems.

Problem description

  1. Swiping AppBarLayout quickly will bounce back.
  2. Quickly slide The AppBarLayout to the folded state, and immediately pull down the jitter phenomenon;
  3. You can’t use your finger to stop scrolling while swiping AppBarLayout like RecyclerView.

Problem analysis

It’s all the fault of AppBarLayout’s inertial sliding events.

The solution

gradle

Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io'}}}Copy the code

Step 2. Add the dependency in your app build.gradle:

dependencies {
	implementation 'com. Making. Yuruiyin: AppbarLayoutBehavior: v1.0.2'
}
Copy the code

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>Copy the code

From (github.com/yuruiyin/Ap…) . In fact, from the inertia of AppBarLayout slide operation, at the right time to stop the inertia slide. Students who are interested in how to solve the problem can directly look at the source code research, but also hope to have any problem partners can propose issues to discuss with each other.

conclusion

This article doesn’t go into the details of how to solve the problem, but I believe it will do the trick because you can happily use a nearly perfect AppBarLayout using the AppBarLayoutBehavior described above. Isn’t that enough? No, of course not, because as the saying goes, we should not only know what it is, we should know why. So, I encourage you to look at the source code for AppbarLayoutBehavior.

digression

If you think the content of this article is helpful to everyone, please give a thumbs up