您的位置:首页 > 移动开发 > Android开发

Android 补件动画 TweenAnimation 简单DEMO

2016-06-05 20:17 429 查看
透明度动画AlphaAnimation

旋转动画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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 动画