手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android 动画之RotateAnimation应用详解
Android 动画之RotateAnimation应用详解
摘要:android中提供了4中动画:AlphaAnimation透明度动画效果ScaleAnimation缩放动画效果TranslateAnim...

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应用详解1

【Android 动画之RotateAnimation应用详解】相关文章:

Android开发之OpenGL ES 旋转glRotatef

Android开发之OpenGL ES 基础

Android自定义属性 format的深入解析

Android Studio使用教程图文详解

android帮助文档打开慢的三种解决方法

Android动画之ScaleAnimation

Android 原始资源文件的使用详解

Android之PreferenceActivity应用详解(2)

Android笔记之:App模块化及工程扩展的应用

android中Invalidate和postInvalidate的更新view区别

精品推荐
分类导航