动画Animation

public class MainActivity extends Activity {

	private ImageView iv;

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

		iv = (ImageView) findViewById(R.id.iv);
	}

	// 透明动画
	public void alpha(View v) {
		AlphaAnimation aa = new AlphaAnimation(1.0f, 0.0f);
		// 设置动画的时长
		aa.setDuration(3000);
		// 设置播放重复次数
		aa.setRepeatCount(2);
		// reverse反向 restart正向
		aa.setRepeatCount(Animation.REVERSE);
		iv.startAnimation(aa);
	}
	/**
	 * float fromX 动画起始时 X坐标上的伸缩尺寸
	 * float toX 动画结束时 X坐标上的伸缩尺寸 
	 * float fromY动画起始时Y坐标上的伸缩尺寸 
	 * float toY 动画结束时Y坐标上的伸缩尺 
	 * int pivotXType 动画在X轴相对于物件位置类型 
	 * float pivotXValue 动画相对于物件的X坐标的开始位置 
	 * int pivotYType 动画在Y轴相对于物件位置类型 
	 * float pivotYValue 动画相对于物件的Y坐标的开始位置
	 * 
	 */
	//缩放动画
	public void scale(View v) {
		ScaleAnimation sa = new ScaleAnimation(0, 1.0f, 0, 1.0f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		sa.setDuration(3000);
		sa.setRepeatCount(2);
		sa.setRepeatMode(Animation.REVERSE);
		iv.startAnimation(sa);
	}
	/**
	 * fromXType 起始点X坐标相对于自身还是相对于父控件
		fromXValue X坐标上的起始位置
		toXType 终点X坐标相对于自身还是相对于父控件
		toXValue X坐标上的终点位置
		fromYType 起始点Y坐标相对于自身还是相对于父控件
		fromYValue Y坐标上的起始位置
		toYType 终点Y坐标相对于自身还是相对于父控件
		toYValue Y坐标上的终点位置
	 */
	//位移动画
	public void trans(View v){
		TranslateAnimation ta=new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
				Animation.RELATIVE_TO_PARENT, 0.5f,
				Animation.RELATIVE_TO_PARENT, 0, 
				Animation.RELATIVE_TO_PARENT, 0.5f);
		ta.setDuration(3000);
		ta.setRepeatCount(4);
		ta.setRepeatMode(Animation.REVERSE);
		iv.startAnimation(ta);
	}
	//旋转动画
	public void rotate(View v) {
		RotateAnimation ra = new RotateAnimation(0, 360,
				Animation.RELATIVE_TO_SELF, 1.0f,
				Animation.RELATIVE_TO_SELF, 1.0f);
		ra.setDuration(3000);
		ra.setRepeatCount(3);
		ra.setRepeatMode(Animation.REVERSE);
		iv.startAnimation(ra);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值