12_View动画-集合

package com.itheima.animation;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;


public class MainActivity extends Activity {


ImageView iv ; 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView)findViewById(R.id.iv);
}




public void translate(View v){
//定义平移动画
/*TranslateAnimation anim = new TranslateAnimation(
0, 50, 
0, 200);*/

/**
*  Animation.ABSOLUTE :代表的是后面给定的值是绝对的长度, 像素个数。
*  
*   Animation.RELATIVE_TO_SELF : 参照的是自己的宽高倍数 , 后面的值说的是倍数
*   

*   
* Animation.RELATIVE_TO_PARENT : 代表的是父元素的倍数: 在这代表整个屏幕

*/

TranslateAnimation anim = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0, 
Animation.RELATIVE_TO_PARENT, 0.5f, 
Animation.RELATIVE_TO_PARENT, 0, 
Animation.RELATIVE_TO_PARENT, 0.5f);

//定义时间长度
anim.setDuration(2000);

//设置动画无限循环播放
anim.setRepeatCount(Animation.INFINITE);

//设置动画循环的模式 , reverse ,播放完毕之后,倒着播放
anim.setRepeatMode(Animation.REVERSE);

//指定让这个控件播放当前的动画
iv.startAnimation(anim);

}




public void rotate(View v){

RotateAnimation anim  = new RotateAnimation(
0, 360 , //从什么角度旋转到什么角度
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);

// 定义时间长度
anim.setDuration(2000);


// 设置动画无限循环播放
anim.setRepeatCount(Animation.INFINITE);


// 设置动画循环的模式 , reverse ,播放完毕之后,倒着播放
anim.setRepeatMode(Animation.REVERSE);


// 指定让这个控件播放当前的动画
iv.startAnimation(anim);
}

public void scale(View v){

ScaleAnimation anim = new ScaleAnimation(
1, -1, //初始的倍数到什么倍数
1, -1/**/, 
Animation.RELATIVE_TO_SELF, 0.5f, //从自己的中心缩放
Animation.RELATIVE_TO_SELF, 0.5f);


// 定义时间长度
anim.setDuration(2000);


// 设置动画无限循环播放
anim.setRepeatCount(Animation.INFINITE);


// 设置动画循环的模式 , reverse ,播放完毕之后,倒着播放
anim.setRepeatMode(Animation.REVERSE);


// 指定让这个控件播放当前的动画
iv.startAnimation(anim);
}


public void alpha (View v){

//从半透明到不透明  0.0---完全透明  1.0 --- 完全不透明
AlphaAnimation anim = new AlphaAnimation(0.5f, 1.0f);

// 定义时间长度
anim.setDuration(2000);


// 设置动画无限循环播放
anim.setRepeatCount(Animation.INFINITE);


// 设置动画循环的模式 , reverse ,播放完毕之后,倒着播放
anim.setRepeatMode(Animation.REVERSE);


// 指定让这个控件播放当前的动画
iv.startAnimation(anim);
}


public void set(View v){


RotateAnimation anim  = new RotateAnimation(
0, 360 , //从什么角度旋转到什么角度
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);

// 定义时间长度
anim.setDuration(2000);


// 设置动画无限循环播放
anim.setRepeatCount(Animation.INFINITE);


// 设置动画循环的模式 , reverse ,播放完毕之后,倒着播放
anim.setRepeatMode(Animation.REVERSE);


ScaleAnimation sanim = new ScaleAnimation(
3, -3, //初始的倍数到什么倍数
3, -3/**/, 
Animation.RELATIVE_TO_SELF, 0.5f, //从自己的中心缩放
Animation.RELATIVE_TO_SELF, 0.5f);


// 定义时间长度
sanim.setDuration(2000);


// 设置动画无限循环播放
sanim.setRepeatCount(Animation.INFINITE);


// 设置动画循环的模式 , reverse ,播放完毕之后,倒着播放
sanim.setRepeatMode(Animation.REVERSE);


//shareInterpolator  --是否共用同一个插入器
//true ---里面的子动画共用集合的插入器
//false - -子动画使用自己的插入器

//声明一个动画集合
AnimationSet set = new AnimationSet(false);

//往集合里面添加动画
set.addAnimation(anim);

set.addAnimation(sanim);

//让控件播放集合中的动画
iv.startAnimation(set);

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值