【问题标题】:Android FAB Animation when new Activity starts or Resume to previous Activity新 Activity 启动或恢复到以前的 Activity 时的 Android FAB 动画
【发布时间】:2015-10-24 06:10:30
【问题描述】:

我想为我的FAB(浮动操作按钮)制作动画。

我的目标在这个 youtube 视频中展示: Video

有人知道我如何动画我的FAB,以及xml 文件中的动画效果如何?

谢谢。

【问题讨论】:

    标签: android animation material-design floating-action-button


    【解决方案1】:
    public void hideView(final View view) {
        view.animate()
                .translationY(view.getHeight()+YOUR MARGIN)
                .setDuration(300)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                    }
                });
    }
    
    public void showView(final View view) {
        view.animate()
                .translationY(0)
                .setDuration(300)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                    }
                });
    }
    

    已编辑:

    for i sec wait call it from :

    handler.postDelayed(new Runnable(){
            @Override
            public void run() {
                showView(...)
            }
        }, 1000);
    

    你可能必须在 run 中使用 runOnUiThread(new Runnable(...))

    重新编辑:

    public void hideView(final View view) {
    view.animate()
            .translationY(-10)
            .setDuration(30)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.animate()
                      .translationY(view.getHeight()+YOUR MARGIN + 10)
                      .setDuration(300)
                      .setListener(new AnimatorListenerAdapter() {
                      @Override
                      public void onAnimationEnd(Animator animation) {
                          super.onAnimationEnd(animation);
                      }
                  });
                }
            });
    

    }

    【讨论】:

    • 在 onResume(..) 中添加 showView(...) 并在 onClick 中添加 hideView(...) 或任何触发意图的东西
    • 您必须调用 hideView 才能看到翻译
    • 我怎样才能得到这样的效果,即 FAB 等待一秒钟然后关闭?喜欢这个 youtube 视频吗?
    • 不幸的是没有:-(问题是FAB显示在教程的前面和后面的活动中......
    • 你所要做的就是以正确的方式调用方法,你能解释一下你目前得到的是什么吗?..有什么区别?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 2012-07-28
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2012-09-06
    相关资源
    最近更新 更多