AppBarLayout.setExpanded (boolean, true) weird animation in the support library 23.1.1

In my application, I deploy or shorten AppBarLayout to a specific event using setExpanded(boolean, true) .

I have a good result, with instant animation using com.android.support:design:23.1.0 , then I upgraded to 23.1.1 , and the animation turned out to be very slow and not quite fast.

In the android.support.design.widget.AppBarLayout source code, I found a problem in animateOffsetTo (under the public static class Behavior extends HeaderBehavior<AppBarLayout> ), which in version 23.1.0 was something like this:

 private void animateOffsetTo(final CoordinatorLayout coordinatorLayout, final AppBarLayout child, int offset) { if (mAnimator == null) { mAnimator = ViewUtils.createAnimator(); mAnimator.setInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR); mAnimator.setUpdateListener(new ValueAnimatorCompat.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimatorCompat animator) { setHeaderTopBottomOffset(coordinatorLayout, child, animator.getAnimatedIntValue()); } }); } else { mAnimator.cancel(); } mAnimator.setIntValues(getTopBottomOffsetForScrollingSibling(), offset); mAnimator.start(); } 

And in version 23.1.1 it looks like this:

 private void animateOffsetTo(final CoordinatorLayout coordinatorLayout, final AppBarLayout child, final int offset) { final int currentOffset = getTopBottomOffsetForScrollingSibling(); if (currentOffset == offset) { if (mAnimator != null && mAnimator.isRunning()) { mAnimator.cancel(); } return; } if (mAnimator == null) { mAnimator = ViewUtils.createAnimator(); mAnimator.setInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR); mAnimator.setUpdateListener(new ValueAnimatorCompat.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimatorCompat animator) { setHeaderTopBottomOffset(coordinatorLayout, child, animator.getAnimatedIntValue()); } }); } else { mAnimator.cancel(); } // Set the duration based on the amount of dips we're travelling in final float distanceDp = Math.abs(currentOffset - offset) / coordinatorLayout.getResources().getDisplayMetrics().density; mAnimator.setDuration(Math.round(distanceDp * 1000 / ANIMATE_OFFSET_DIPS_PER_SECOND)); mAnimator.setIntValues(currentOffset, offset); mAnimator.start(); } 

How can I change the expand / contract animation and make it faster?

+43
android android-support-library android-support-design
Nov 24 '15 at 11:24
source share
2 answers
+2
Feb 22 '17 at 12:13
source share

Just upgrade the library to version 25.3.1.

+1
May 08 '17 at 14:43
source share



All Articles