21

根据新的Android Design Guidelines for the Floating Action Button,将 Floating Action Button 转换为 Toolbar应该是合理的。

是否有任何样本/示例来执行这种转换?

4

2 回答 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();
    }
}

通过这种方式,您应该能够创建动画。这是使用它的方法。只需在您的工厂 onClick() 方法中应用它

于 2015-04-30T12:53:56.750 回答
5

在我看来,它就像一个显示自定义工具栏的循环显示动画

于 2015-04-30T12:40:37.823 回答