【问题标题】:Floating action button start up animation浮动动作按钮启动动画
【发布时间】:2015-06-16 18:04:31
【问题描述】:

我在网上搜索了一段时间,但似乎在任何地方都找不到。我有一个浮动操作按钮,我已经工作了。它显示出来并且是可点击的等,但此时没有任何连接。在我继续之前,我想知道如何让它在启动时动画化。

在 FAB 的材料设计页面上,它显示为一个新芽类型的动画,它来自正确的位置,但动画到其预期大小。 Found here.

感谢任何信息。

【问题讨论】:

  • 内置动画使用:floatButton.hide()(或显示);

标签: android android-animation


【解决方案1】:

您可以查看FloatingActionButton 内部的Behavior 类。例如输入动画是这样实现的:

private void animateIn(FloatingActionButton button) {
    button.setVisibility(0);
    if(VERSION.SDK_INT >= 14) {
        ViewCompat.animate(button).scaleX(1.0F).scaleY(1.0F).alpha(1.0F).setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR).withLayer().setListener((ViewPropertyAnimatorListener)null).start();
    } else {
        Animation anim = android.view.animation.AnimationUtils.loadAnimation(button.getContext(), anim.fab_in);
        anim.setDuration(200L);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        button.startAnimation(anim);
    }
}

【讨论】:

  • 你好!那么这会放在FloatingActionButtonFragment 类的onCreateView() 中吗?还是会像behavior.animateIn(FAB)?不确定这将在什么上下文中使用
  • 是的,但您可能希望动画仅在savedInstanceState == null 第一次播放时播放。
  • 我在 api 中找不到animateIn。介意链接我或编辑您的答案以反映我如何实施它。我找到了FloatingActionButton.Behavior 类,但有nothing about animation in there
  • 它不是一个公共 api,这就是我向你指出它的原因。在内部,它与 CoordinatorLayout 结合使用。要使用它,您需要自己实现它。
【解决方案2】:

你想在这里使用AnimationUtils。这是一个简单的教程:Android Animations

【讨论】:

    猜你喜欢
    • 2015-03-11
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多