I'm trying to create a circular reveal animation that starts at the center of a View (API 21+). I tried using the averages of View.getLeft() and View.getRight() for x and View.getTop() and View.getBottom() for y (which is what the sample does, but if my View is offset by CoordinatorLayout, the values are wrong. I'm grabbing the values in an OnPreDrawListener, so the View has already been measured.
I've found that using View.getDrawingRect() does the trick.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With