`
kakukemeit
  • 浏览: 31684 次
  • 性别: Icon_minigender_2
  • 来自: 南京
社区版块
存档分类
最新评论

Android 动画之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坐标的伸缩值。

详细出处参考:http://www.jb51.net/article/32341.htm

参数解释:

Animation.RELATIVE_TO_SELF, 0.5f------相对自己,0.5;设置了图片的旋转点,即为中心点;

 

package com.example.animitation_rotate;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {

	private ImageView image;
	private Button start;
	private Button end;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		image = (ImageView) findViewById(R.id.image_view);
		start = (Button) findViewById(R.id.start);
		end = (Button) findViewById(R.id.end);

		/** 设置旋转动画 */
		final RotateAnimation animation = new RotateAnimation(0f, 360f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		animation.setDuration(5000);// 设置动画持续时间

		/** 常用方法 */
		// animation.setRepeatCount(int repeatCount);//设置重复次数
		// animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态
		// animation.setStartOffset(long startOffset);//执行前的等待时间

		start.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				image.setAnimation(animation);

				/** 开始动画 */
				image.startAnimation(animation);
			}
		});

		end.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				/** 结束动画 */
				image.clearAnimation();
			}
		});
	}

}

 

 

程序包:

 

  • 大小: 21.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics