В моем приложении я разворачиваю или сокращаю AppBarLayout
на конкретное событие с помощью setExpanded(boolean, true)
.
У меня хороший результат, с мгновенной анимацией, используя com.android.support:design:23.1.0
, затем я обновился до 23.1.1
, и анимация получилась очень медленной и не совсем быстрой.
В исходном коде android.support.design.widget.AppBarLayout
я нашел проблему в animateOffsetTo
(под public static class Behavior extends HeaderBehavior<AppBarLayout>
), что в версии 23.1.0 было примерно так:
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();
}
И в версии 23.1.1 выглядит так:
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();
}
Как я могу изменить анимацию expand/contract и сделать быстрее?