2013-11-26 205 views
4

我想旋轉沿其x axis.I視圖試圖做到以下幾點:如何旋轉沿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 axis.How可旋轉我完成x軸旋轉?

回答

5

使用一個ObjectAnimator這樣的:

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

ObjectAnimator的類做旋轉沿着軸線對於被作爲參數傳遞給ofFloat方法傳遞的視圖。

如果您只想旋轉一次視圖,請不要設置任何重複次數。

answer from "its-tomweber"正在完美工作。