【发布时间】:2019-05-03 19:23:02
【问题描述】:
我想在FloatingActionButton上制作这种类型的动画
我尝试过的
public void animFab() {
ObjectAnimator scaleX = ObjectAnimator.ofFloat(fab, View.SCALE_X, from, to);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(fab, View.SCALE_Y, from, to);
ObjectAnimator translationZ = ObjectAnimator.ofFloat(fab, View.TRANSLATION_Z, from, to);
AnimatorSet set1 = new AnimatorSet();
set1.playTogether(scaleX, scaleY, translationZ);
set1.setDuration(500);
set1.setInterpolator(new AccelerateInterpolator());
set1.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
}
});
ObjectAnimator scaleXBack = ObjectAnimator.ofFloat(fab, View.SCALE_X, to, from);
ObjectAnimator scaleYBack = ObjectAnimator.ofFloat(fab, View.SCALE_Y, to, from);
ObjectAnimator translationZBack = ObjectAnimator.ofFloat(fab, View.TRANSLATION_Z, to, from);
Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.lineTo(0.5f, 1.3f);
path.lineTo(0.75f, 0.8f);
path.lineTo(1.0f, 1.0f);
PathInterpolator pathInterpolator = new PathInterpolator(path);
AnimatorSet set2 = new AnimatorSet();
set2.playTogether(scaleXBack, scaleYBack, translationZBack);
set2.setDuration(500);
set2.setInterpolator(pathInterpolator);
final AnimatorSet set = new AnimatorSet();
set.playSequentially(set1, set2);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
set.start();
}
});
set.start();
}
问题
上面的代码在 Lolipop 及以上设备上工作正常,但在 KitKat 设备上不工作
以下是我尝试过的一些链接
- Animating Fab on click (zoom in/out)
- ObjectAnimator starting with a frame jump on Android 4.4 (nexus 5) but not in 4.1 device
- Implementing ImageView transition between activities for pre-Lollipop devices.
- How to achieve Transition animation in Pre lollipop devices
- Material Transitions in pre lollipop apps
- Android ImageView Zoom-in and Zoom-out Continuously
谁能帮忙解决奇巧设备中的问题
如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。
【问题讨论】:
-
也许这个库会帮助你github.com/beworker/…
-
“不在 KitKat 上工作”究竟是什么意思?
-
@azizbekian 应用程序崩溃,因为在 api 级别 21 中添加了
PathInterpolator和ObjectAnimator.ofFloat(fab, View.TRANSLATION_Z, to, from)
标签: java android android-layout android-animation floating-action-button