1

I have a problem with the "View.animate().withEndAction()" function in Android.

Most of the time the code below works perfectly, animation is fine etc. But in about 5% of the cases, "// doSomething1 " isn't executed. But I've never experienced a case where doSomething1 is triggered, but doSomething2 isn't. So I'm thinking there must be a fault on my side.

I've been working 2 days on this issiue, but I can't come up with an solution, neither can I find anything related to this issiue on the Internet. So my best bet is on you guys.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i,long l) {

            hideCardAnimation();

            card_view.animate().withEndAction(new Runnable() {
                @Override
                public void run() {
                    //doSomething 2
                }
            });

     }
});



private void hideCardAnimation(){

    main_button.animate().scaleX(LauncherSettings.buttonScale * 0.8f)
    .scaleY(LauncherSettings.buttonScale * 0.8f)
    .setDuration(300)
    .setStartDelay(0)
    .withEndAction(new Runnable() {
        @Override
        public void run() {

    //  doSomething 1

            main_button.animate().alpha(0)
            .setDuration(500);

            card_view.animate().rotationY(15)
            .alpha(0)
            .scaleX(0.65f)
            .scaleY(0.65f)
            .translationX(-300)
            .setDuration(500)
            .setStartDelay(500);
        }
    });

    card_highlight.animate().alpha(0)
    .setStartDelay(0)
    .setDuration(500);

    options_button.animate().translationX(options_button.getWidth())
    .alpha(0f)
    .setDuration(500);
}
jose praveen
  • 1,298
  • 2
  • 10
  • 17

1 Answers1

1

It seems there's nothing you can do about this issue.

Finally I gave up and used a handler which post was delayed exactly the amount of time the animation took.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459