ViewAnimationUtils - No animation occurs

143 views Asked by At

I'm trying to use a Circular Reveal to animate in a LinearLayout on click of a FAB.

Onclick, the view changes to become visible after a time delay, but no visible animation runs? In addition, when the function is reversed as an exit animation the view is invisible for the duration of the animation.

The code:

//Rest of method triggered onClick Above
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        circleReveal(formcontainer,addnewbutton);
        ObjectAnimator.ofFloat(addnewbutton, "translationY", -heightbutton).start();
    }
}

public void circleReveal(LinearLayout formLayout, FloatingActionButton fab) {

    int cx = (fab.getLeft() + fab.getRight()) / 2;
    int cy = (fab.getTop() + fab.getBottom()) / 2;

    int radius = Math.max(formLayout.getWidth(), formLayout.getHeight());

    Animator reveal = createCircularReveal(formLayout, cx, cy, 0, radius);

    formLayout.setVisibility(View.VISIBLE);
    reveal.setDuration(2000);
    reveal.start();
}

Many thanks in advance for your help!

[EDIT] After testing, i've noticed that it's just this view that it fails on? Every other view in my layout that i've tried works fine?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/formcontainer"
              android:background="@android:color/white"
              android:layout_width="match_parent"
              android:layout_height="65dp"
              android:orientation="vertical"
              android:baselineAligned="false"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:gravity="bottom"
              android:layout_marginBottom="0dp"
              android:elevation="4dp"
              android:layout_alignParentBottom="true">

[EDIT 2] So, i've partially solved the issue, in that the animation now works, but only when the centre is not calculated from the FAB?

1

There are 1 answers

0
George Mount On BEST ANSWER

The circular animation runs with respect to the View itself. So, your center should be:

int cx = fab.getWidth() / 2;
int cy = fab.getHeight() / 2;