四种动画
来源:互联网 发布:神行者定位软件 编辑:程序博客网 时间:2024/06/07 18:42
private ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取资源ID
image=(ImageView) findViewById(R.id.image);
}
//位移
public void translate(View v){
/**
* fromXType 开始X轴的类型. One of Animation.ABSOLUTE,绝对的 Animation.RELATIVE_TO_SELF,相对于自身 or Animation.RELATIVE_TO_PARENT. 相对于父窗体
* fromXValue X轴开始的位置.
* toXType 结束X轴的类型 One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* toXValue X轴结束的位置
* fromYType 开始Y轴的类型
* fromYValue 开始Y轴的位置
* toYType Y轴结束的类型
* toYValue Y轴结束的位置
*/
TranslateAnimation translateAnimation=new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.8f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.8f);
//设置执行的时间
translateAnimation.setDuration(3000);
//设置是否来回执行 RESTART 正常 REVERSE 来回执行
translateAnimation.setRepeatMode(Animation.REVERSE);
//设置执行的次数
translateAnimation.setRepeatCount(2);
//是否保存最后的位置
translateAnimation.setFillAfter(true);
//设置插值器
translateAnimation.setInterpolator(new AccelerateInterpolator());
//执行动画
// image.setAnimation(translateAnimation);
image.startAnimation(translateAnimation);
}
//旋转
public void rotate(View v){
/**
*
* fromDegrees, 开始的角度
* toDegrees, 结束的角度
* pivotXType X轴原点的类型
* pivotXValue, X原点的位置
* pivotYType, Y轴原点的类型
* pivotYValue Y原点的位置
*/
RotateAnimation rotateAnimation=new RotateAnimation(0, -360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//设置执行的时间
rotateAnimation.setDuration(3000);
//设置执行的次数
rotateAnimation.setRepeatCount(2);
//设置是否来回执行 RESTART 正常 REVERSE 来回执行
rotateAnimation.setRepeatMode(Animation.REVERSE);
image.startAnimation(rotateAnimation);
}
//透明
public void alpha(View v){
/**
* fromAlpha, 开始透明
* toAlpha 结束透明
*/
AlphaAnimation alphaAnimation=new AlphaAnimation(1.0f, 0.0f);
alphaAnimation.setDuration(3000);
alphaAnimation.setRepeatCount(2);
image.startAnimation(alphaAnimation);
}
//缩放
public void scale(View v){
/**
* fromX, 开始X轴水平的位置
* toX, 结束X轴水平的位置
* fromY, 开始Y轴水平的位置
* toY,结束Y轴水平的位置
* pivotXType, 规定原点的类型以及位置
* pivotXValue,
* pivotYType,
* pivotYValue
*
*/
ScaleAnimation scaleAnimation=new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(3000);
scaleAnimation.setRepeatCount(1);
//重复执行
scaleAnimation.setRepeatMode(Animation.REVERSE);
image.startAnimation(scaleAnimation);
}
//组合动画
public void set(View v){
//是否使用通用一个插值器
AnimationSet animationSet=new AnimationSet(true);
AlphaAnimation alphaAnimation=new AlphaAnimation(1.0f, 0.0f);
RotateAnimation rotateAnimation=new RotateAnimation(0, -360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ScaleAnimation scaleAnimation=new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
TranslateAnimation translateAnimation=new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.8f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.8f);
//将动画添加到组合动画当中
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(translateAnimation);
animationSet.setDuration(10000);
image.startAnimation(animationSet);
animationSet.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.i("TAG", "开始");
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.i("TAG", "重复");
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.i("TAG", "结束");
}
});
}
阅读全文
0 0
- Android四种动画
- CAAnimation四种动画
- CAAnimation四种动画
- Android四种动画
- 四种动画
- android中的四种动画
- Animation四种动画详解
- Android四种常见动画
- View的四种动画,
- 60_四种动画
- Android 动画效果(二):四种基础动画的 **动态设置、动画监听、组合动画
- Tween动画(四种)以及Activity间跳转动画
- android学习-动画(基本的四种动画)
- 传统动画Animation的四种基础动画的使用
- 传统动画Animation的四种基础动画的使用
- 传统动画Animation的四种基础动画的使用
- Android 四种动画效果的调用
- android-Animation 四种基本动画
- 每天一道算法题——LeeCode.389. Find the Difference
- 正整数去重取最大值
- 2264 Card Game (First Edition)
- API接口安全性设计
- __int64 与long long 的区别, C/C++的64位整型 不同编译器间的比较
- 四种动画
- 内核函数前面单下划线和双下划线
- HDU6164(计算几何--点关于直线的对称点)
- [Leetcode] 370. Range Addition 解题报告
- 系统API接口规范
- iOS Navigation Bar 导航栏折腾记 (Swift&OC)
- 答辩应该注意的几个问题
- hdu 4729 An Easy Problem for Elfness (树链剖分-入边-二分-查区间最值)
- fzu-2265