支持库23.1.1中的AppBarLayout.setExpanded(boolean,true)奇怪的animation
在我的应用程序中,我使用setExpanded(boolean, true)
在特定事件上展开或收缩AppBarLayout
。
我有一个很好的结果,用com.android.support:design:23.1.0
一个活泼和stream畅的animation,然后我更新到23.1.1
和animation变得非常缓慢,不活泼。
在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(); }
如何更改展开/合同animation并使其更快?
这个问题被报告和修复
只需要更新库到25.3.1版本。