浮动操作按钮扩展

21

您可以使用揭示动画。单击浮动操作按钮时,您可以启动动画以显示所需的工具栏。当然,浮动操作按钮将仅具有该功能。 - Atlas91
尝试查看我的回答。 - Atlas91
2个回答

13
为使用揭示动画,您需要在onCreateView回调函数中向视图添加onLayoutChange监听器,如下所示:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Inflate the layout for this fragment
        final View view = inflater.inflate(R.layout.fragment_map_list, container, false);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    v.removeOnLayoutChangeListener(this);
                    revealView(view);
                }
            });
        }
        return view;
    }

revealView()方法将会在这里:

private void revealView(View view) {

    toolbar = view.findViewById(R.id.mytoolbar);

    int cx = (view.getLeft() + view.getRight()) / 2;
    int cy = (view.getTop() + view.getBottom()) / 2;
    float radius = Math.max(infoContainer.getWidth(), infoContainer.getHeight()) * 2.0f;

    if (infoContainer.getVisibility() == View.INVISIBLE) {
        infoContainer.setVisibility(View.VISIBLE);
        ViewAnimationUtils.createCircularReveal(infoContainer, cx, cy, 0, radius).start();
    } else {
        Animator reveal = ViewAnimationUtils.createCircularReveal(
                infoContainer, cx, cy, radius, 0);
        reveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                toolbar.setVisibility(View.INVISIBLE);
            }
        });
        reveal.start();
    }
}

通过这种方式,您应该能够创建自己的动画。这是使用它的方法。只需将其应用于您的fab onClick() 方法即可。


这看起来不错。我会尽快测试它。 - Knossos
好的,告诉我吧 ;) - Atlas91
1
我现在没有时间测试它,但是通过阅读你的代码,圆形揭示看起来就是我需要的。 - Knossos
你能否在你的回答中添加一些XML呢?我有些变量不理解。 - JMR
3
什么是infoContainer? - Igor Janković

5

在我看来,这似乎是一个圆形揭示动画,它展现了一个自定义的工具栏。


那看起来像是另一个答案所做的,感谢提供参考! - Vince

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接