设为首页 加入收藏

TOP

Android中TweenAnimation四种动画切换效果(二)
2014-11-24 03:14:24 来源: 作者: 【 】 浏览:9
Tags:Android TweenAnimation 动画 切换 效果
rotateAnimation.setDuration(3000);
rotateAnimation.setRepeatCount(3);
//启动动画
imageView.startAnimation(rotateAnimation);
break;
case Scale:
//定义缩放动画,从中心坐标开始,缩放1.5倍大小,持续1分钟,重复三次
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1.5f, 1, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(3000);
scaleAnimation.setRepeatCount(3);
//启动动画
imageView.startAnimation(scaleAnimation);
break;
case Translate:
//定义移动动画,都从自身坐标开始,移动2个位置,持续1分钟,重复三次
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
translateAnimation.setDuration(3000);
translateAnimation.setRepeatCount(3);
//启动动画
imageView.startAnimation(translateAnimation);
break;


case Complex:
//设置复杂的操作步骤,点击按钮complex后,会运行四种动画效果叠加
AnimationSet sets = new AnimationSet(false);
//定义渐变动画
AlphaAnimation _animation1 = new AlphaAnimation(1f, 0.1f);
_animation1.setDuration(3000);
//定义旋转动画,在物体的中心位置
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setDuration(3000);
//定义缩放动画,从中心坐标开始,缩放1.5倍大小
ScaleAnimation scaleAnimation1 = new ScaleAnimation(1, 1.5f, 1, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation1.setDuration(3000);
//定义移动动画,都从自身坐标开始,移动2个位置
TranslateAnimation translateAnimation1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
translateAnimation1.setDuration(3000);
//启动动画
sets.addAnimation(_animation1);
sets.addAnimation(rotateAnimation1);
sets.addAnimation(scaleAnimation1);
sets.addAnimation(translateAnimation1);
imageView.startAnimation(sets);
break;
default:
break;
}
}
}
}


layout文件:


< xml version="1.0" encoding="utf-8" >
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qa" />
android:id="@+id/Alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alpha" />
android:id="@+id/Rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate" />
android:id="@+id/Scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scale" />
android:id="@+id/Translate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Translate" />
android:id="@+id/Complex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Complex" />


资源anim文件alpha.xml


< xml version="1.0" encoding="utf-8" >
xmlns:android="http://schemas.android.com/apk/res/android"
android

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下shell编程常用grep\awk\se.. 下一篇如何让Android应用支持多种语言

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何利用Python做数 (2025-12-24 23:48:36)
·如何使用python进行 (2025-12-24 23:48:34)
·python 爬虫入门该怎 (2025-12-24 23:48:31)
·Java 实现多个大文件 (2025-12-24 23:22:00)
·Java多线程编程在工 (2025-12-24 23:21:56)