Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to rotate a view along x axis

I want to rotate a view along its 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 i instead the view rotates along its y axis.How can i accomplish x axis rotation?

like image 527
Jack Wachira Avatar asked Feb 15 '23 13:02

Jack Wachira


1 Answers

Use an ObjectAnimator like this:

    ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationX", 0.0f, 360f);
    animation.setDuration(5000);
    animation.setRepeatCount(ObjectAnimator.INFINITE);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.start();
like image 56
Mann Avatar answered Mar 29 '23 23:03

Mann