As per https://developer.android.com/training/material/animations.html
The
ViewAnimationUtils.createCircularReveal()
method enables you to animate a clipping circle to reveal or hide a view.To reveal a previously invisible view using this effect:
// previously invisible view View myView = findViewById(R.id.my_view); // 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 finalRadius = Math.max(myView.getWidth(), myView.getHeight()); // create the animator for this view (the start radius is zero) Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius); // make the view visible and start the animation myView.setVisibility(View.VISIBLE); anim.start();
This is meant to reveal a view. How can I use this to circularly reveal an entire activity, without any shared elements?
Specifically, I'd like my searchActivity to circularly reveal from the search action button in the toolbar.
ou have to draw the circle view, and after that you should create an animation to it.
Creating the circle view:
Creating the animation class to set the new angle:
Put circle into your layout:
And finally starting the animation:
To reverse the
CircularReveal
animation swap thestartRadius
andendRadius
arguments. Also you will need to setup anAnimatorListener
and in theonAnimationEnd()
callback method is where you can callfinishAfterTransition()
. This is for when you press theup navigation
or click on theback button
.If you want to reverse the circular reveal on leaving activity, use the following modification to onBackPressed().
I think you can use
ActivityOptionsCompat.makeClipRevealAnimation
.[https://developer.android.com/reference/android/support/v4/app/ActivityOptionsCompat.html#makeClipRevealAnimation(android.view.View, int, int, int, int)](https://developer.android.com/reference/android/support/v4/app/ActivityOptionsCompat.html#makeClipRevealAnimation(android.view.View, int, int, int, int))
After looking for a solution for half a day without a result, I came up with an own implementation. I'm using a transparent activity with a matching root layout. The root layout is a view which can then be revealed with
createCircularReveal()
.My code looks like this:
Theme Definition in styles.xml
Activity Definition in AndroidManifest.xml
then I declared a layout for my activity (I've chosen DrawerLayout, so that I can have a NavDrawer. Every layout should work here.)
Important is the FrameLayout with the id
root_layout
. This view will be revealed in the activity.Finally I implemented
CircularRevealActivity
and overwroteonCreate()
:It was important to put
circularRevealActivity()
into aOnGlobalLayoutListener
, because the view needs to be drawn for the animation.circularRevealActivity()
looks like Ishaan's proposal:Edit 1
The definition for
R.anim.do_not_move
was added. However, it should work without that line too, if your design does not specify default transitions for activities. Let me knowR.anim.do_not_move: