在我的应用中,我使用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();
}
如何更改展开/收缩动画并使其更快?