After finding a solution in the afternoon with no result, I came up with my own implementation. I use transparent activity with a suitable root layout. The root layout is a view that can then be discovered using createCircularReveal() .
My code is as follows:
Defining a theme in styles.xml
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowIsTranslucent">true</item> <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> </style>
Determining activity in AndroidManifest.xml
<activity android:name=".ui.CircularRevealActivity" android:theme="@style/Theme.Transparent" android:launchMode="singleTask" />
then I declared a layout for my activity (I chose DrawerLayout, so I can have NavDrawer. Each layout should work here.)
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <FrameLayout android:id="@+id/root_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/honey_melon" > </FrameLayout> </android.support.v4.widget.DrawerLayout>
Important is FrameLayout with the identifier root_layout . This view will be revealed in this activity.
Finally, I implemented CircularRevealActivity and overwrite onCreate() :
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.do_not_move, R.anim.do_not_move); setContentView(R.layout.activity_reveal_circular); if (savedInstanceState == null) { rootLayout.setVisibility(View.INVISIBLE); ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { circularRevealActivity(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } } }
It was important to put circularRevealActivity() in the OnGlobalLayoutListener , because you need to draw for animation.
circularRevealActivity() looks like Ishan's suggestion:
private void circularRevealActivity() { int cx = rootLayout.getWidth() / 2; int cy = rootLayout.getHeight() / 2; float finalRadius = Math.max(rootLayout.getWidth(), rootLayout.getHeight());
Change 1
Added definition for R.anim.do_not_move . However, it should work without this line if your project does not specify default transitions for actions. Let me know
R.anim.do_not_move:
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0" android:toYDelta="0" android:duration="@android:integer/config_mediumAnimTime" /> </set>