标签:无限 imageview lan dup htm tox init 角度 地址
在很久之前写过Android之动画1,然而当时只是好玩的态度玩玩而已,许多知识都没有介绍完整。
现归纳一下。
Android的基本动画有:平移、旋转、缩放、和透明度。
这里各来一个例子:
先看平移:
fromXType 水平播放的类型
fromXValue 从哪开始,0表示现在的位置
toXType, 到什么位置的类型
toXValue 到什么坐标
fromYType 垂直播放的类型
fromYValue 从哪开始,0表示现在的位置
toYType 到什么位置的类型
toYValue 到什么坐标
TranslateAnimation translate = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, -2,
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1);
//设置显示时间
translate.setDuration(3000);
//播放资源为无限循环
translate.setRepeatCount(Animation.INFINITE);
//播放模式,反转播放,先顺着播完,就反着播放
translate.setRepeatMode(Animation.REVERSE);
//哪个组件在播放,设置
imageView.setAnimation(translate);
//开始播放
translate.start();
旋转:
/*
* fromDegrees, 从什么角度开始 0 从现在的 toDegrees, 270度 pivotXType, X中心点类型
* Animation.RELATIVE_TO_SELF自身 pivotXValue, 中心点值 0.5表示这个图片的一半置
* pivotYType, Y中心点类型Animation.RELATIVE_TO_SELF自身
* pivotYValue 0.5f
*/
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
3);
//播放显示时间
rotate.setDuration(5000);
rotate.setRepeatCount(Animation.INFINITE);
rotate.setRepeatMode(Animation.RESTART);
imageView.setAnimation(rotate);
rotate.start();
缩放:
/*
* fromX, toX, 从坐标什么地址开始到什么坐标,0,表示当前 fromY, toY,
* pivotXType, 旋转的中心点
* pivotXValue, 类型, pivotYType, pivotYValue
*/
ScaleAnimation scale = new ScaleAnimation(1, 2, 1, -2,
Animation.RELATIVE_TO_SELF, -2, Animation.RELATIVE_TO_SELF, 3);
// 播放显示时间
scale.setDuration(5000);
scale.setRepeatCount(Animation.INFINITE);
scale.setRepeatMode(Animation.RESTART);
imageView.setAnimation(scale);
scale.start();
最后透明度:
/*
* fromAlpha, 从什么透明度开始
* toAlpha 到什么透明度结束
*/
AlphaAnimation alpha = new AlphaAnimation(1, 0);
// 播放显示时间
alpha.setDuration(2000);
alpha.setRepeatCount(Animation.INFINITE);
alpha.setRepeatMode(Animation.REVERSE);
imageView.setAnimation(alpha);
alpha.start();
}
标签:无限 imageview lan dup htm tox init 角度 地址
原文地址:http://www.cnblogs.com/caidupingblogs/p/6095918.html