我有2个不同的应用程序,它们将在工具栏上执行汉堡到箭头的动画。
两个应用都使用implementation 'com.android.support:design:27.1.1'
https://www.youtube.com/watch?v=i0-vmhOQPB0&feature=youtu.be
https://www.youtube.com/watch?v=1DljB0rskWE&feature=youtu.be
真正让我感到困惑的是,为什么会有2种不同的动画。两个应用程序都使用相同的支持库,具有相同的动画代码。
private static class ActionBarDrawerToggleEx extends android.support.v7.app.ActionBarDrawerToggle {
public ActionBarDrawerToggleEx(Activity activity, DrawerLayout drawerLayout,
Toolbar toolbar, @StringRes int openDrawerContentDescRes,
@StringRes int closeDrawerContentDescRes) {
super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes);
}
public void enableAnimation(boolean enable) {
enableAnimation = enable;
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, enableAnimation ? slideOffset : 0);
}
private volatile boolean enableAnimation = true;
}
private void animateHamburgerToArrow() {
actionBarDrawerToggle.enableAnimation(true);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.addListener(new ValueAnimator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
actionBarDrawerToggle.enableAnimation(false);
arrowVisible = true;
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
anim.addUpdateListener(valueAnimator -> {
float slideOffset = (Float) valueAnimator.getAnimatedValue();
actionBarDrawerToggle.onDrawerSlide(null, slideOffset);
});
anim.setInterpolator(new DecelerateInterpolator());
// You can change this duration to more closely match that of the default animation.
anim.setDuration(300);
anim.start();
}
知道为什么相同的代码会产生不同的动画吗?
答案 0 :(得分:0)
好。我想通了。动画上的差异是由这种样式引起的。
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">false</item>
<item name="color">@android:color/white</item>
</style>
<style name="Theme.MyApp.Base.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>