`
dowhathowtodo
  • 浏览: 778433 次
文章分类
社区版块
存档分类
最新评论

RotateAnimation类:旋转变化动画类

 
阅读更多

RotateAnimation类:旋转变化动画类

RotateAnimation类是Android系统中的旋转变化动画类,用于控制View对象的旋转动作,该类继承于Animation类。RotateAnimation类中的很多方法都与Animation类一致,该类中最常用的方法便是RotateAnimation构造方法。

【基本语法】public RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

参数说明

fromDegrees:旋转的开始角度。

toDegrees:旋转的结束角度。

pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。

pivotXValue:X坐标的伸缩值。

pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。

pivotYValue:Y坐标的伸缩值。

【实例演示】下面通过代码来演示如何设置一个简单的旋转变化动画效果。

  1. publicclassfirstActivityextendsActivity{
  2. /**Calledwhentheactivityisfirstcreated.*/
  3. @Override
  4. publicvoidonCreate(BundlesavedInstanceState){//重载onCreate方法
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.main);
  7. finalImageViewimage=(ImageView)findViewById(R.id.imageView1);//ImageView对象
  8. Buttonbtn1=(Button)findViewById(R.id.button1);//按钮对象
  9. Buttonbtn2=(Button)findViewById(R.id.button2);
  10. finalAnimationrotateAnimation=new
  11. RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
  12. //设置旋转变化动画对象
  13. btn1.setOnClickListener(newView.OnClickListener(){//设置监听器
  14. @Override
  15. publicvoidonClick(Viewv){
  16. //TODOAuto-generatedmethodstub
  17. rotateAnimation.setDuration(3000);//持续时间
  18. image.setAnimation(rotateAnimation);//设置动画
  19. rotateAnimation.startNow();//启动动画
  20. }
  21. });
  22. btn2.setOnClickListener(newView.OnClickListener(){//设置监听器
  23. @Override
  24. publicvoidonClick(Viewv){
  25. //TODOAuto-generatedmethodstub
  26. rotateAnimation.cancel();//取消动画执行
  27. }
  28. });
  29. }
  30. }
在这段代码中,首先通过RotateAnimation构造方法创建了一个旋转变化的动画对象。然后,在第一个按钮监听器中设置了动画的持续时间,之后启动该动画。在第二个按钮监听器中取消该动画
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics