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(); }
How can I change the expand / contract animation and make it faster?
android android-support-library android-support-design
Nifhel Nov 24 '15 at 11:24 2015-11-24 11:24
source share