Android 动画之RotateAnimation应用详解

时间:2022-08-17 17:03:07 

android中提供了4中动画:
AlphaAnimation 透明度动画效果
ScaleAnimation 缩放动画效果
TranslateAnimation 位移动画效果
RotateAnimation 旋转动画效果

本节讲解RotateAnimation 动画,
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐标的伸缩值。
int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐标的伸缩值。
代码:


public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.main_img);
start = (Button) findViewById(R.id.main_start);
cancel = (Button) findViewById(R.id.main_cancel);
/** 设置旋转动画 */
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);//设置动画持续时间
/** 常用方法 */
//animation.setRepeatCount(int repeatCount);//设置重复次数
//animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态
//animation.setStartOffset(long startOffset);//执行前的等待时间
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 开始动画 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 结束动画 */
animation.cancel();
}
});
}
}


效果:
Android 动画之RotateAnimation应用详解

标签:Android动画,RotateAnimation
0
投稿

猜你喜欢

  • 在.net应用程序中运行其它EXE文件的方法

    2023-11-08 08:34:43
  • ADO.NET实体数据模型详细介绍

    2023-10-16 12:15:41
  • java 算法之归并排序详解及实现代码

    2021-12-27 01:52:11
  • Mybatis 入参类型方式全面详解

    2023-10-16 20:03:40
  • Java DecimalFormat 保留小数位及四舍五入的陷阱介绍

    2023-11-09 04:49:33
  • JDK常用命令jps jinfo jstat的具体说明与示例

    2021-08-09 16:03:30
  • IDEA的默认快捷键设置与Eclipse的常用快捷键的设置方法

    2023-04-09 18:32:40
  • java获取包下被指定注解的类过程解析

    2023-08-08 11:12:27
  • Spring Security使用Lambda DSL配置流程详解

    2021-12-23 19:20:32
  • android中图片的三级缓存cache策略(内存/文件/网络)

    2023-09-04 19:51:59
  • Java中URL传中文时乱码的解决方法

    2022-05-17 02:16:55
  • MyBatis找不到mapper文件的实现

    2023-12-15 09:22:11
  • Java中如何避免sql注入实例详解

    2022-08-24 14:42:06
  • C# pictureBox用法案例详解

    2022-02-24 19:40:07
  • windows系统配置Java开发环境变量

    2022-03-07 23:28:07
  • SpringBoot Http远程调用的方法

    2022-07-22 04:08:33
  • Java8 CompletableFuture runAsync学习总结submit() execute()等

    2023-05-25 04:13:43
  • PowerManagerService之手动灭屏流程示例分析

    2023-01-13 17:11:51
  • Java统计字符串中字符出现次数的方法示例

    2023-11-25 08:23:02
  • Java中使用HashMap时指定初始化容量性能解析

    2023-01-01 11:05:27
  • asp之家 软件编程 m.aspxhome.com