您的位置:首页 > 其它

动画Animation

2016-05-17 20:08 155 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: