欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 动画之RotateAnimation应用详解

程序员文章站 2023-12-05 17:20:16
android中提供了4中动画: alphaanimation 透明度动画效果 scaleanimation 缩放动画效果 translateanimation 位移动画效...
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应用详解