如何沿x轴旋转视图

时间:2013-11-26 10:54:24

标签: android-animation

我想沿x轴旋转视图。我尝试执行以下操作:

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);

但我改为视图沿y轴旋转。我如何完成x轴旋转?

2 个答案:

答案 0 :(得分:6)

使用像这样的ObjectAnimator:

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

答案 1 :(得分:1)

ObjectAnimator类沿着轴旋转,作为参数传递给ofFloat方法的视图。

如果只想旋转视图一次,请不要设置任何重复计数。

answer from "its-tomweber"工作正常。