YaZao RuZakiaga
YaZao RuZakiaga

Reputation: 101

Slide Right to Left using ObjectAnimation

I can do the slide left to right thanks to the sample code given in this YouTube link:

https://www.youtube.com/watch?v=3UbJhmkeSig

However I can't do the right to left animation. What I've tried is putting a '-' (negative) sign in the code below but it wont work and it gives me the error:

Operator '-' cannot be applied to 'android.util.Property

ObjectAnimator translateAnimation =
                ObjectAnimator.ofFloat(view, -View.TRANSLATION_X, 800);
        translateAnimation.start();
        translateAnimation.setRepeatCount(1);
        translateAnimation.setRepeatMode(ValueAnimator.REVERSE);

Any way to do this inside an Activity?

Upvotes: 1

Views: 989

Answers (1)

manfcas
manfcas

Reputation: 1951

You should work on the value, while the property name should remain the same:

ObjectAnimator translateAnimation =
            ObjectAnimator.ofFloat(view, View.TRANSLATION_X, -view.getWidth());
    translateAnimation.start();
    translateAnimation.setRepeatCount(1);
    translateAnimation.setRepeatMode(ValueAnimator.REVERSE);

Upvotes: 1

Related Questions