zoukankan      html  css  js  c++  java
  • RotateAnimation 旋转动画

    引用:http://www.alnton.com/?p=343

    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. public class firstActivity extends Activity {  
    2. /** Called when the activity is first created. */  
    3. @Override  
    4. public void onCreate(Bundle savedInstanceState) {           //重载onCreate方法  
    5.     super.onCreate(savedInstanceState);  
    6.     setContentView(R.layout.main);  
    7.  
    8.     final ImageView image=(ImageView)findViewById(R.id.imageView1); //ImageView对象  
    9.     Button btn1=(Button)findViewById(R.id.button1);         //按钮对象  
    10.     Button btn2=(Button)findViewById(R.id.button2);  
    11.     final Animation rotateAnimation = new       
    12.      RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);  
    13.                                                         //设置旋转变化动画对象  
    14.     btn1.setOnClickListener(new View.OnClickListener() {        //设置监听器  
    15.           
    16.         @Override  
    17.         public void onClick(View v) {  
    18.             // TODO Auto-generated method stub  
    19.             rotateAnimation.setDuration(3000);              //持续时间  
    20.             image.setAnimation(rotateAnimation);            //设置动画  
    21.             rotateAnimation.startNow();                 //启动动画  
    22.         }  
    23.     });  
    24.     btn2.setOnClickListener(new View.OnClickListener() {        //设置监听器  
    25.           
    26.         @Override  
    27.         public void onClick(View v) {  
    28.             // TODO Auto-generated method stub  
    29.             rotateAnimation.cancel();                       //取消动画执行  
    30.         }  
    31.     });  
    32. }  
    33. }  

    在这段代码中,首先通过RotateAnimation构造方法创建了一个旋转变化的动画对象。然后,在第一个按钮监听器中设置了动画的持续时间,之后启动该动画。在第二个按钮监听器中取消该动画。读者运行这段代码,将看到图片沿如图9.8所示的方向进行旋转。

  • 相关阅读:
    高度地形Unity3D 通过代码导入自定义格式地形的方法
    初始化提交CI跟swfupload结合 出现302的解决方案
    文件信息我的学习生涯(Delphi篇) 11
    相机三星如果我可以设计HTC ONE的相机
    数据数据库Apache Derby数据库
    安装索引源码阅读工具 lxr 安装配置初探
    模板替换php实战 第三天
    应用程序安装实验四十六微软应用程序虚拟化之一APPV 5.1服务器部署
    函数应用SAEPython教程(一) 在SAE上进行Python的开发
    消息方法熬之滴水穿石:Delphi曾经的利器(5)
  • 原文地址:https://www.cnblogs.com/sode/p/2696296.html
Copyright © 2011-2022 走看看