How to rotate a view along the x axis

I want to rotate the view along the x axis. I tried to do the following:

AnimationSet anim=new AnimationSet(true);
RotateAnimation rotate=new      RotateAnimation(0.0f,-10.0f,RotateAnimation.ABSOLUTE,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f);
rotate.setFillAfter(true);
rotate.setDuration(5000);
rotate.setRepeatCount(0);
anim.addAnimation(rotate);
View relatv1=(View)findViewById(R.id.relativeLayout1);
relatv1.setAnimation(anim);

but instead, the view rotates along its y axis. How can I rotate the x axis?

+4
source share
2 answers

Use ObjectAnimator as follows:

    ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationX", 0.0f, 360f);
    animation.setDuration(5000);
    animation.setRepeatCount(ObjectAnimator.INFINITE);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.start();
+5
source

The class ObjectAnimatorrotates along the axis for the view, which is passed as an argument to the method ofFloat.

If you want to rotate the view only once, do not set the number of repetitions.

The answer from "its-tomweber" works fine.

+1
source

All Articles