补间动画TweenAnimation-简单使用
2018-03-31 00:42
423 查看
1.补间动画有4种基本类型
透明度变化alpha , 大小变化scale , 位移变化translate , 旋转变化rotate每种类型都有两种实现方式,xml资源方式 和 代码方式.
2.资源方式所有资源xml代码
在res/anim 中创建 补间动画文件alphaanimation.xml<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
> <!--用了一个默认的插值器,可以性控制动画变化速度-->
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0"
/> <!-- 0表示完全透明 -->
</set>scaleanimation.xml<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<scale
android:duration="2000"
android:fromXScale="0.2"
android:fromYScale="0.2"
android:toXScale="1.5"
android:toYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
/>
<!--
android:fromXScale 缩放开始尺寸
android:toXScale="1.5" 缩放结束尺寸
android:pivotX 缩放中心位置
-->
</set>translateanimation.xml<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"> <!--可以设置插值器-->
<translate
android:duration="2000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="500"
/>
<!--
android:fromXDelta 开始位置
android:toXDelta 结束位置
-->
</set>rotateanimation.xml<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><!--可以设置一个插值器-->
<rotate
android:duration="2000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatMode="restart"
android:repeatCount="-1"
android:startOffset="0"
/>
<!--
android:fromDegrees 开始时角度
android:toDegrees 结束时角度
通用属性:
android:repeatMode reverse表示倒序回放,restart表示从头播放
android:startOffset 等待开始运行的时间,单位为毫秒
android:repeatCount 重复次数 -1表示一直重复
-->
</set>
3.调用xml资源显示动画方式,及代码显示动画方式
//AlphaAnimation-资源方式 //imag1.setBackgroundResource(R.anim.alphaanimation); //该方法不行 Animation alphaanimation1 = AnimationUtils.loadAnimation(this, R.anim.alphaanimation); //必须用该方法 imag1.setAnimation(alphaanimation1); //AlphaAnimation-代码方式 AlphaAnimation alphaAnimation2 = new AlphaAnimation(0 , 1); //透明度从0到1 alphaAnimation2.setDuration(5000); alphaAnimation2.setFillAfter(true); //动画结束后保留结束时状态 alphaAnimation2.setInterpolator(new AccelerateDecelerateInterpolator());//用了一个插值器,控制变化速度 imag2.setAnimation(alphaAnimation2);
//ScaleAnimation-资源方式 Animation scaleanimation1 = AnimationUtils.loadAnimation(this , R.anim.scaleanimation); imag1.setAnimation(scaleanimation1); //ScaleAnimation-代码方式 ScaleAnimation scaleAnimation2 = new ScaleAnimation(1.0f , 4.0f , 1.0f , 4.0f , 0.0f , 0.0f); //参数分别为:fromx .tox , fromy , toy , pivox , pivoy scaleAnimation2.setDuration(5000); scaleAnimation2.setFillAfter(true); imag2.setAnimation(scaleAnimation2);
//TranslateAnimation-资源方式 Animation translateanimation1 = AnimationUtils.loadAnimation(this , R.anim.translateanimation); imag1.setAnimation(translateanimation1); //TranslateAnimation-代码方式 TranslateAnimation translateAnimation2 = new TranslateAnimation(0f , 500f , 0f , 0f); //参数分别为:fromx , tox , fromy , toy translateAnimation2.setDuration(5000); translateAnimation2.setFillAfter(true); imag2.setAnimation(translateAnimation2);
//RotateAnimation-资源方式 Animation rotateanimation1 = AnimationUtils.loadAnimation(this , R.anim.rotateanimation); imag1.setAnimation(rotateanimation1); //RotateAnimation-代码方式 RotateAnimation rotateAnimation2 = new RotateAnimation(90f , 0f , 0.5f , 0.5f); //参数分别为:fromDegres , toDegress , pivox , pivoy //如果开始的角度小于结束的角度,则顺时针转,否则逆时针转 rotateAnimation2.setDuration(5000); rotateAnimation2.setFillAfter(true); imag2.setAnimation(rotateAnimation2);
4.ok,简单使用到此为止
相关文章推荐
- Android中的补间动画(tween)的简单使用
- Android补间动画(Tween Animation)的使用总结
- Tween Animation 补间动画 xml中的简单实现
- 使用 补间动画(Tween Animation)
- 史上最简单android动画之Tween Animation(渐变动画)
- android 补间动画 tween animation xml基本属性
- iOS开发 动画Animation的简单使用
- Android开发之tween(补间动画)动画及其使用场景(界面切换、弹窗等)详解
- tween.js 用户指南 - 与 Three.js 配合使用的补间动画库
- Android动画主要包含补间动画(Tween)View Animation、帧动画(Frame)Drawable Animation、以及属性动画Property Animation
- Android动画之补间动画(Tween Animation)实例详解
- Android 动画之二 View Animation —— 补间(Tween)动画与Interpolator的介绍
- Android动画效果之Tween Animation(补间动画)(一)
- 补间动画(Tween Animation)
- android补间动画(Tween Animation)
- Android动画效果Animation之Tween实现简单动画
- Android动画1-补间动画(TweenAnimation)
- Android Animation Tween动画效果的使用
- android补间动画(tween animation)xml基本属性
- Android动画之补间动画(Tween Animation)