Reputation: 12467
I want to hide a View
, starting at a x,y coordinate and expand this hide animation outward. Is this possible?
Essentially, this is the opposite of a circular reveal. I'm fine with this being a minSdk 21.
extra details
I have ActivityB
(with a transluscent background) on top of ActivityA
. AcitivityA
has already been created, but it's not yet visible to the user. When you click the done button in the bottom right corner, I want to reveal ActivityA
by hiding ActivityB
(using the expanding circular hide animation, which starts where the user pressed the done button.)
Upvotes: 1
Views: 2306
Reputation: 2641
You're thinking about this the opposite way. You say you want to hide Activity B
but at the same time you're showing Activity A
.
It's like looking at a half empty glass. It's half full and half empty. Both are true.
Try this :
Show Activity B
. When you click done, show Activity A
(with a transparent background) and start the reveal animation.
However, if you insist on the hiding part, here's how to do it.
View myView = findView(R.id.awesome_card);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the final radius for the clipping circle
int dx = Math.max(cx, myView.getWidth() - cx);
int dy = Math.max(cy, myView.getHeight() - cy);
float finalRadius = (float) Math.hypot(dx, dy);
SupportAnimator animator =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, finalRadius, 0);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(1500);
animator.start();
Instead of starting from 0, start from finalRadius.
I recommend using a transparent background for all activities to avoid OVERDRAW for performance purposes.
For other users who are trying to achieve the Circular Reveal on Pre-Lollipop devices, this is the right library(CircularReveal) to do it. On pre-lollipop, it uses its own implementation. On lollipop and above, it uses the native implementation.
Upvotes: 3