Android 补件动画 TweenAnimation 简单DEMO
2016-06-05 20:17
429 查看
透明度动画AlphaAnimation
旋转动画RotateAnimation
缩放动画ScaleAnimation
平移缩放动画TranslateAnimation
动画集合AnimationSet
效果图
DEMO
在res/anim/下建立一个名为
用
通过代码直接实现
通过代码直接实现
通过代码直接实现
通过代码直接实现
![](http://img.blog.csdn.net/20160605210719242)
旋转动画RotateAnimation
缩放动画ScaleAnimation
平移缩放动画TranslateAnimation
动画集合AnimationSet
效果图
DEMO
透明度动画AlphaAnimation
通过XML文件实现在res/anim/下建立一个名为
alpha.xml动画文件
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:repeatMode="restart"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0"/> </set>
用
AnimationUtils去加载动画文件
Animation animation= AnimationUtils.loadAnimation(this,R.anim.alpha); mIv.startAnimation(animation);
通过代码直接实现
AlphaAnimation alphaAnimation=new AlphaAnimation(0,1);//开始 结束 透明度 alphaAnimation.setDuration(3000);//时长:3秒 alphaAnimation.setRepeatMode(Animation.RESTART);//重复方式 reverse反向 restart 重新 alphaAnimation.setRepeatCount(4);//重复次数 也可以说是infinite 无限循环 //alphaAnimation.setInterpolator(); 速度 mIv.startAnimation(alphaAnimation);
旋转动画RotateAnimation
通过XML文件实现<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000"> <rotate android:fromDegrees="0" android:toDegrees="180" android:pivotX="50%" android:pivotY="50%"/> </set>
//加载xml文件方式实现 Animation animation=AnimationUtils.loadAnimation(this,R.anim.rotate); mIv.startAnimation(animation);
通过代码直接实现
//使用代码直接实现 RotateAnimation rotateAnimation=new RotateAnimation(0,30,0,0); rotateAnimation.setFillAfter(true);//停在最后一桢 //参数说明 开始角度 结束角度 轴心x坐标 轴心y坐标 rotateAnimation.setDuration(3000); mIv.startAnimation(rotateAnimation);
缩放动画ScaleAnimation
通过XML文件实现<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000"> <scale android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="2" android:toYScale="2" /> </set>
// //加载xml文件方式实现 Animation animation=AnimationUtils.loadAnimation(this,R.anim.scale); // animation.setFillEnabled(true); animation.setFillAfter(true); mIv.startAnimation(animation);
通过代码直接实现
//使用代码直接实现 ScaleAnimation scaleAnimation=new ScaleAnimation(1,2,1,2); //参数说明 开始时 x缩放系数 结束时x缩放系数 开始时 y缩放系数 结束时y缩放系数 scaleAnimation.setFillAfter(true);//停在最后一帧 scaleAnimation.setDuration(3000); mIv.startAnimation(scaleAnimation);
平移缩放动画TranslateAnimation
通过XML文件实现<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="4000"> <translate android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="90" android:toYDelta="90"/> </set>
//xml文件方式实现 Animation animation= AnimationUtils.loadAnimation(this,R.anim.translate); mIv.startAnimation(animation);
通过代码直接实现
//代码方式 TranslateAnimation translateAnimation = new TranslateAnimation(0, 200, 0, 200); //参数说明 开始 x结束 x 坐标 开始 y结束 y坐标 translateAnimation.setDuration(3000); mIv.startAnimation(translateAnimation);
动画集合AnimationSet
AnimationSet animationSet=new AnimationSet(true); animationSet.setDuration(3000); animationSet.addAnimation(new AlphaAnimation(0,1)); animationSet.addAnimation(new RotateAnimation(0,360)); animationSet.addAnimation(new ScaleAnimation(1,2,1,2)); animationSet.addAnimation(new TranslateAnimation(0,100,0,100)); animationSet.setFillAfter(true); mIv.startAnimation(animationSet);
效果图
DEMO
http://pan.baidu.com/s/1c2HPUHa相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories