支持库23.1.1中的AppBarLayout.setExpanded(boolean,true)奇怪的动画 [英] AppBarLayout.setExpanded(boolean, true) weird animation in support library 23.1.1
问题描述
在我的应用中,我使用 setExpanded(boolean,true)
在特定事件上扩展或缩小 AppBarLayout
。
In my app I expand or contract the AppBarLayout
on a specific event using setExpanded(boolean, true)
.
使用 com.android.support:design:23.1.0
,然后我将其更新为 23.1.1
,动画变得非常慢,而且一点也不活泼。
I've got a good result, with a snappy and fluid animation using com.android.support:design:23.1.0
, then I updated to 23.1.1
and the animation got very slow and not snappy at all.
在 android.support.design.widget.AppBarLayout
的源代码中,我在 animateOffsetTo
中找到了问题(在公共静态类下的行为扩展HeaderBehavior< AppBarLayout>
),在版本23.1.0中是这样的:
In the source code of android.support.design.widget.AppBarLayout
, I located the problem in animateOffsetTo
(under public static class Behavior extends HeaderBehavior<AppBarLayout>
), that in the version 23.1.0 was 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();
}
在版本23.1.1中是这样的:
And in the version 23.1.1 is 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 is faster?
推荐答案
这篇关于支持库23.1.1中的AppBarLayout.setExpanded(boolean,true)奇怪的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!