Android 反向循环狂欢动画

Android 反向循环狂欢动画,android,reverse,circularreveal,Android,Reverse,Circularreveal,我想制作一个简单的动画,我将尝试描述它。在第一,屏幕中间有一个小圆圈,然后当你按下它时,圆形动画显示一个矩形按钮。我不知道我是否用了最好的方法,但它在这里 circle.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid and

我想制作一个简单的动画,我将尝试描述它。在第一,屏幕中间有一个小圆圈,然后当你按下它时,圆形动画显示一个矩形按钮。我不知道我是否用了最好的方法,但它在这里

circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid android:color="@color/circle_color"></solid>

    <size
        android:width="50dp"
        android:height="50dp"/>
</shape>
到目前为止一切正常。接下来,我想做反向的圆形显示动画-基本上是我刚刚创建的相同动画,只是反向,这样在最后我会有我的小圆圈和按钮会消失


有人能给我一些提示吗?

我已经尝试了一些方法来解决你的问题,希望能对你有所帮助

image.setOnClickListener(new ImageView.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    revealShow(button, true);
                }
            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    revealShow(image, false);
                }
            }
        });
//这是revealShow方法,您可以根据需要更改动画持续时间

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void revealShow(View view, boolean isExpand) {

        int w = view.getWidth();
        int h = view.getHeight();

        int endRadius = (int) Math.hypot(w, h);

        int cx = (int) (image.getX() + (image.getWidth() / 2));
        int cy = (int) (image.getY() + (image.getHeight() / 2));


        if (isExpand) {
            Animator revealAnimator = ViewAnimationUtils.createCircularReveal(fragments_container, cx, cy, 0, endRadius);

            image.setVisibility(View.INVISIBLE);
            button.setVisibility(View.VISIBLE);
            revealAnimator.setDuration(500);
            revealAnimator.start();

        } else {

            Animator anim =
                    ViewAnimationUtils.createCircularReveal(fragments_container, cx, cy, endRadius, image.getWidth() / 2);

            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    image.setVisibility(View.VISIBLE);
                    button.setVisibility(View.INVISIBLE);
                }
            });
            anim.setDuration(500);
            anim.start();
        }
    }

非常感谢你,伙计!我没有意识到在
createCircularVeal
函数中我可以指定大于起始半径的结束半径:)非常感谢你的努力,伙计!
image.setOnClickListener(new ImageView.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    revealShow(button, true);
                }
            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    revealShow(image, false);
                }
            }
        });
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void revealShow(View view, boolean isExpand) {

        int w = view.getWidth();
        int h = view.getHeight();

        int endRadius = (int) Math.hypot(w, h);

        int cx = (int) (image.getX() + (image.getWidth() / 2));
        int cy = (int) (image.getY() + (image.getHeight() / 2));


        if (isExpand) {
            Animator revealAnimator = ViewAnimationUtils.createCircularReveal(fragments_container, cx, cy, 0, endRadius);

            image.setVisibility(View.INVISIBLE);
            button.setVisibility(View.VISIBLE);
            revealAnimator.setDuration(500);
            revealAnimator.start();

        } else {

            Animator anim =
                    ViewAnimationUtils.createCircularReveal(fragments_container, cx, cy, endRadius, image.getWidth() / 2);

            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    image.setVisibility(View.VISIBLE);
                    button.setVisibility(View.INVISIBLE);
                }
            });
            anim.setDuration(500);
            anim.start();
        }
    }