安卓(Android) 怎么实现圆形隐藏视图(View)

2019年10月14日21:51:20安卓(Android) 怎么实现圆形隐藏视图(View)已关闭评论 346 909字阅读3分1秒

1.简介

安卓(Android) 怎么实现圆形隐藏视图(View)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;

import android.view.View;
import android.view.ViewAnimationUtils;

public class Main {
    public static final int ANIMATION_DURATION_SHORT = 250;

    @TargetApi(21)
    public static void circleHideView(final View view,
            AnimatorListenerAdapter listenerAdapter) {
        circleHideView(view, ANIMATION_DURATION_SHORT, listenerAdapter);
    }

    @TargetApi(21)
    public static void circleHideView(final View view, int duration,
            AnimatorListenerAdapter listenerAdapter) {
        int cx = view.getWidth();
        int cy = view.getHeight() / 2;

        float initialRadius = (float) Math.hypot(cx, cy);

        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx,
                cy, initialRadius, 0);

        anim.addListener(listenerAdapter);

        if (duration > 0) {
            anim.setDuration(duration);
        } else {
            anim.setDuration(ANIMATION_DURATION_SHORT);
        }
        anim.start();
    }
}

 
继续阅读
编程十万个怎么办