Skip to content

Instantly share code, notes, and snippets.

@keyboardr
Created July 7, 2015 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyboardr/572a5eae9f57be286c24 to your computer and use it in GitHub Desktop.
Save keyboardr/572a5eae9f57be286c24 to your computer and use it in GitHub Desktop.
Centered circular reveal animator
@TargetApi(VERSION_CODES.LOLLIPOP)
private Animator createCenteredReveal(View view) {
// Could optimize by reusing a temporary Rect instead of allocating a new one
Rect bounds = new Rect();
view.getDrawingRect(bounds);
int centerX = bounds.centerX();
int centerY = bounds.centerY();
int finalRadius = Math.max(bounds.width(), bounds.height());
return ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0f, finalRadius);
}
@keyboardr
Copy link
Author

If you're ok sacrificing a little performance, you can also fix the timing with the following:

int width = bounds.width();
int height = bounds.height();
int finalRadius = (int) (Math.sqrt(width * width + height * height));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment