Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to play an ObjectAnimator sequentially with a playTogether

Tags:

java

android

This may be a dumb question but I'm not quite sure how to go about playing an ObjectAnimator and then two other ObjectAnimators who should be played together in sequential order.

I have an image that I'm trying to rotate and then move diagonally. In order to move the image diagonally I made an AnimatorSet and am playing the two ObjectAnimators together (one for the x direction and another for the y direction).

The problem is that I'm not sure how to add all three animators to the animatorSet while playing the first before the second two which play together (hope that makes sense).

This is what I have so far but I'm definitely missing something.

            as.play(ObjectAnimator.ofFloat(ship, "rotation", sangle, angle).setDuration(1000));

            ObjectAnimator x = ObjectAnimator.ofFloat(ship, "translationX", rx, rx2);
            ObjectAnimator y = ObjectAnimator.ofFloat(ship, "translationY", ry, ry2);
            as.playTogether(x, y);
            as.setDuration(3000);
            as.start();

            setshipanimation();

I'm familiar with the .before function but I don't know how to get that to work with the .playTogether function :S

Really appreciate all help!

like image 983
texas techie 213 Avatar asked Aug 25 '18 23:08

texas techie 213


1 Answers

Try this:

final AnimatorSet set = new AnimatorSet();

final AnimatorSet subSet = new AnimatorSet();
subSet.playTogether(
        ObjectAnimator.ofFloat(ship, "translationX", rx, rx2),
        ObjectAnimator.ofFloat(ship, "translationY", ry, ry2));

set.playSequentially(
        ObjectAnimator.ofFloat(ship, "rotation", sangle, angle)
                .setDuration(1000),
        subSet.setDuration(3000));

set.start();
like image 66
Akaki Kapanadze Avatar answered Nov 05 '22 21:11

Akaki Kapanadze