Java 如何连续设置晶圆厂按钮(放大/缩小)的动画?

Java 如何连续设置晶圆厂按钮(放大/缩小)的动画?,java,android,android-layout,android-animation,floating-action-button,Java,Android,Android Layout,Android Animation,Floating Action Button,我想在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 =

我想在
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设备

下面是我尝试过的一些链接

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();


}
有人能帮助解决KitKat设备中的问题吗

如果需要更多信息,请务必让我知道。提前谢谢。感谢您的努力。

您看到“Field requires API 21”Studio lint错误,因为以下代码行在棒棒糖上运行时应用程序会中止

ObjectAnimator translationZ = ObjectAnimator.ofFloat(fab, View.TRANSLATION_Z, from, to);
ObjectAnimator translationZBack = ObjectAnimator.ofFloat(fab, View.TRANSLATION_Z, to, from);
PathInterpolator pathInterpolator = new PathInterpolator(path);
正如您所知,这些特性是在API21中引入的,而早期的API不提供这些特性,这就是您看到这些错误的原因。但是,可以使用从支持库获取路径插值器

用于创建基于路径的
[插值器]的帮助器(https://developer.android.com/reference/android/view/animation/Interpolator.html)
实例。在API 21或更新版本上,将使用平台实现,而在较旧的平台上,将使用兼容的替代实现

我不认为你需要一个“z”翻译的解决方案。(我真的看不出有和没有任何区别,但那可能只是我自己。无论如何,晶圆厂已经有了高度效果的阴影。)

这里是对
animFab()
的一次重做,对其进行了一些修改,以适应21世纪之前的API。 确保您从v4支持库中挂起了
PathInterpolatorCompat
。首先是一段视频,显示在API 19仿真器上工作的代码:


另一种可能是用于可绘制动画,但这将是一个完全重写。

可能此库将帮助您了解“不在KitKat上工作”的实际含义吗?@azizbekian应用程序正在崩溃,因为
PathInterpolator
ObjectAnimator.Offload(fab,View.translationz,to,from)
在api level 21Hey@Cheticamp中添加了它的工作,非常感谢您的解释,如果可能的话,您可以使用“AnimatedVectorDrawableCompat”小悟空提供任何示例代码吗?没问题。至于
AnimatedVectorDrawableCompat
,我还没有使用过它,所以我没有任何示例代码可以共享。