Antonis427 Antonis427 - 2 months ago 17
Android Question

Error while trying to create circular reveal: IllegalStateException: cannot start this animation on a detached view

So, I'm experimenting trying to create a circular reveal on API level 21 on a TextView but I keep getting this error. At first I thought it had something to do with the lifecycle of the fragment I was attempting it but then I just tried the same thing in an activity and it still wouldn't work.

Here's the code:

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
Window w = getWindow();


TextView tv = (TextView) findViewById(;

int a = (tv.getLeft() + tv.getRight()) / 2;
int b = (tv.getTop() + tv.getBottom()) / 2;

int radius = tv.getWidth();

Animator anim = ViewAnimationUtils.createCircularReveal(tv, a, b, 0, radius);



public boolean onCreateOptionsMenu(Menu menu) {

return super.onCreateOptionsMenu(menu);

It's still early days so I can't really find any answers about this. Any ideas?


You're getting the error because the view you passed in hasn't been measured and laid out on the screen yet. ViewAnimationUtils.createCircularReveal needs the target view to be measured to calculate the animation. You'll also find that your variables a and b are always 0.

If you want to experiment, create the animation and start it within a button click listener.