show View with Animation and set duration and radius - Android User Interface

Android examples for User Interface:View Hide Show

Description

show View with Animation and set duration and radius

Demo Code


//package com.java2s;
import android.animation.Animator;

import android.annotation.SuppressLint;

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

public class Main {
    public static final long PERFECT_MILLS = 618;
    public static final int MINI_RADIUS = 0;

    @SuppressLint("NewApi")
    public static void show(View myView, float startRadius,
            long durationMills) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
            myView.setVisibility(View.VISIBLE);
            return;
        }/*  w  ww .ja va 2s  . com*/

        int cx = (myView.getLeft() + myView.getRight()) / 2;
        int cy = (myView.getTop() + myView.getBottom()) / 2;

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

        // ?????? & ???
        int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;

        Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx,
                cy, startRadius, finalRadius);
        myView.setVisibility(View.VISIBLE);
        anim.setDuration(durationMills);
        anim.start();
    }

    public static void show(View myView) {
        show(myView, MINI_RADIUS, PERFECT_MILLS);
    }
}

Related Tutorials