4000 Android RotateAnimation详解
2015-12-25 19:54
411 查看
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坐标的伸缩值。
【实例演示】下面通过代码来演示如何设置一个简单的旋转变化动画效果。
public class firstActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { //重载onCreate方法
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView image=(ImageView)findViewById(R.id.imageView1); //ImageView对象
Button btn1=(Button)findViewById(R.id.button1); //按钮对象
Button btn2=(Button)findViewById(R.id.button2);
final Animation rotateAnimation = new
RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//设置旋转变化动画对象
btn1.setOnClickListener(new View.OnClickListener() { //设置监听器
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
rotateAnimation.setDuration(3000); //持续时间
image.setAnimation(rotateAnimation); //设置动画
rotateAnimation.startNow(); //启动动画
}
});
btn2.setOnClickListener(new View.OnClickListener() { //设置监听器
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
rotateAnimation.cancel(); //取消动画执行
}
});
}
}
在这段代码中,首先通过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坐标的伸缩值。
【实例演示】下面通过代码来演示如何设置一个简单的旋转变化动画效果。
public class firstActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { //重载onCreate方法
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView image=(ImageView)findViewById(R.id.imageView1); //ImageView对象
Button btn1=(Button)findViewById(R.id.button1); //按钮对象
Button btn2=(Button)findViewById(R.id.button2);
final Animation rotateAnimation = new
RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//设置旋转变化动画对象
btn1.setOnClickListener(new View.OnClickListener() { //设置监听器
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
rotateAnimation.setDuration(3000); //持续时间
image.setAnimation(rotateAnimation); //设置动画
rotateAnimation.startNow(); //启动动画
}
});
btn2.setOnClickListener(new View.OnClickListener() { //设置监听器
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
rotateAnimation.cancel(); //取消动画执行
}
});
}
}
在这段代码中,首先通过RotateAnimation构造方法创建了一个旋转变化的动画对象。然后,在第一个按钮监听器中设置了动画的持续时间,之后启动该动画。在第二个按钮监听器中取消该动画
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories