Android Tween Animation
View Animation, 它显示在view向上Tween Animation
Tween动画。本质上没有变化View对象本身。只要改变它绘制
实施方式有两种。一个xml定义,直接在代码中的定义
xml定义方式:
位移动画translate
<? xml version="1.0" encoding="utf-8"? >
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="10"
android:fromYDelta="0"
android:toXDelta="50%"
android:toYDelta="50%p"
android:repeatCount="50"
android:repeatMode="reverse"
android:fillAfter="true">
<!-- repeatCount 动画再次反复的次数
repeatMode 这一次反转上一次的效果
fillAfter 动画结束后,view停留在动画结束时的位置 view的实际位置并没有改变
50%p 相对于父布局
50% 相对于自身
-->
</translate>
旋转动画rotate
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:fillAfter="true">
<!--
fromDegrees="0" 開始角度
toDegrees="-90" 结束角度
pivotX="50%" 中心点x
pivotY="50%" 中心点y
-->
</rotate>
透明度渐变动画alpha
<? xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" >
<!--
fromAlpha 開始的透明度 0全然透明
toAlpha 结束的透明度 1全然不透明
-->
</alpha>
缩放动画scale
<? xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0.5"
android:fromYScale="1"
android:toXScale="3"
android:toYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" >
<!--
scale 缩放比率
-->
</scale>
动画集
<? xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" > <scale
android:fromXScale="0.5"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:toXScale="3"
android:toYScale="2" /> <alpha
android:fromAlpha="0"
android:repeatCount="50"
android:repeatMode="reverse"
android:toAlpha="1" /> <translate
android:fromXDelta="10"
android:fromYDelta="0"
android:repeatCount="50"
android:repeatMode="reverse"
android:toXDelta="50%"
android:toYDelta="50%p" /> <rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:toDegrees="-100" /> </set>
代码载入这些xml定义的动画
Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);
imageview_translate.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_translate.startAnimation(translate); Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
imageview_rotate.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_rotate.startAnimation(rotate); Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);
imageview_alpha.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_alpha.startAnimation(alpha); Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);
imageview_scale.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_scale.startAnimation(scale); Animation set = AnimationUtils.loadAnimation(this, R.anim.set);
imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_set.startAnimation(set);
纯代码创建Tween Animation
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(scale);
animationSet.addAnimation(translate);
animationSet.addAnimation(alpha);
animationSet.addAnimation(rotate);
animationSet.setDuration(2000);
animationSet.setRepeatCount(50);
animationSet.setRepeatMode(Animation.RESTART);
// animationSet.setRepeatMode(Animation.REVERSE);
imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_set.startAnimation(animationSet); TranslateAnimation translateAnimation;
RotateAnimation rotateAnimation;
AlphaAnimation alphaAnimation;
ScaleAnimation scaleAnimation;
// Animation.RELATIVE_TO_SELF 相对于自身
// Animation.RELATIVE_TO_PARENT 相对于父View
设置动画监听器
scale.setAnimationListener(new AnimationListener() { @Override //动画開始
public void onAnimationStart(Animation animation) { } @Override //动画反复
public void onAnimationRepeat(Animation animation) { } @Override //动画结束
public void onAnimationEnd(Animation animation) { }
});
动画插入器Interpolator
在animation的xml和代码中 能够设置动画的插入器。它用来指示动画在持续时间内的动作的速率变化
android:interpolator="@android:anim/overshoot_interpolator"OvershootInterpolator
<!--
默认情况下:动画随着时间的推移 均匀的被应用,要改变这样的效果能够使用插入器
interpolator 设置插入器
accelerate_interpolator 相似加速度先小后大, 開始慢 后渐快 变速运动
accelerate_decelerate_interpolator 相似加速度先大后小, 先加速 后减速 变速运动 anticipate_interpolator the change starts backward then flings forward 先减(减到比開始值还小一点),后加(加到结束值)
anticipate_overshoot_interpolator 先减(减到比開始值还小一点),后加(加到比结束值还大一点。再回退到结束值)
overshoot_interpolator 直接加速到结束值。并比结束值还大一点,再回退到结束值 bounce_interpolator 反弹结束时的变化 到达结束值时一会小一会大 来回两次
cycle_interpolator 先高速从開始到结束值,再遵循正弦模式继续运动 (左右对切,上下对切)
linear_interpolator 相似加速度为0,速率不变, 匀速运动 不定义插入器时使用的默认值 -->
版权声明:本文博主原创文章,博客,未经同意不得转载。
Android Tween Animation的更多相关文章
- 深入Animation,在SurfaceView中照样使用Android—Tween Animation!
第一类:Frame By Frame 帧动画( 不推荐游戏开发中使用) 所谓帧动画,就是顺序播放事先做好的图像,类似于放电影: 分析: 此种方式类似我之 ...
- android tween animation合集
自己写的一些tween animation动画xml文件,可用于activity切换,图片切换动画等 http://files.cnblogs.com/zj2012zy/anim.rar
- android之Tween Animation
android Tween Animation有四种,AlphaAnimation(透明度动画).ScaleAnimation(尺寸伸缩动画).TranslateAnimation(位移动画).Rot ...
- Android动画效果之Tween Animation(补间动画)
前言: 最近公司项目下个版本迭代里面设计了很多动画效果,在以往的项目中开发中也会经常用到动画,所以在公司下个版本迭代开始之前,抽空总结一下Android动画.今天主要总结Tween Animation ...
- Android动画学习(二)——Tween Animation
前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...
- Android动画Animation之Tween用代码实现动画
透明度动画.旋转动画.尺寸伸缩动画.移动动画 package com.javen.tween; import android.annotation.SuppressLint; import andro ...
- Android开发UI之补间动画-Tween Animation
Tween Animation-补间动画 官网链接-http://developer.android.com/reference/android/view/animation/Animation.ht ...
- Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)
1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...
- 详解Android动画之Tween Animation
前面讲了动画中的Frame动画,今天就来详细讲解一下Tween动画的使用. 同样,在开始实例演示之前,先引用官方文档中的一段话: Tween动画是操作某个控件让其展现出旋转.渐变.移动.缩放的这么一种 ...
随机推荐
- Netflix公司监控内部安全的开源项目
Netfix公司已经公布了三个内部工具,用于捕捉黑客在使用互联网服务时留下的痕迹. AndyHoernecke和Netflix公司的云安全团队成员ScottBehrens指出:"很多安全团队 ...
- HDU 2825 AC自动机+DP
题意:一个密码,长度为 n,然后有m个magic words,这个密码至少由k个magic words组成. 问这个密码可能出现的总数. 思路:首先构造AC自动机,由于m很小,才10 ,我们可以使用二 ...
- 关于oracle的备份 导入
****假设要保存为bat文件.最好用汉字 导入: imp clsoftoa/clsoftoa@orcl124 --要导入的数据库的 username/password@数据库名 fromuser= ...
- Mac OS X在建筑Python科学计算环境
经验(比如这篇日志:http://blog.csdn.net/waleking/article/details/7578517).他们推荐使用Mac Ports这种软件来管理和安装全部的安装包.依照这 ...
- MYSQL高可用(HA)随想
记得在上一篇文章“Java集群--大型网站是怎样解决多用户高并发访问的”的结尾处本人阐述了数据库的高可用的一种方案----实现主从部署,那么今天,就让我聊聊本人关于数据库的一些所思所想吧! 下面是本人 ...
- 字符串拼接 拆分 NameValueCollection qscoll = HttpUtility.ParseQueryString(result)
string result = "sms&stat=100&message=发送成功"; string d = HttpUtility.ParseQueryStri ...
- Troubleshooting "Global Enqueue Services Deadlock detected" (Doc ID 1443482.1)
In this Document _afrLoop=1021148011984950&id=1443482.1&displayIndex=1&_afrWindowMode= ...
- 《深入理解mybatis原理》 Mybatis初始化机制具体解释
对于不论什么框架而言.在使用前都要进行一系列的初始化,MyBatis也不例外. 本章将通过下面几点具体介绍MyBatis的初始化过程. 1.MyBatis的初始化做了什么 2. MyBatis基于XM ...
- hdu5384(trie树)
hdu5384 给定n个字符串Ai 给定m个字符串Bi 问所有的Bi在每个Ai中出现了多少次 很显然,对Bi建Trie图,然后每次用Ai去匹配的时候,不断查找当前匹配串的最长后缀,这样就能找到答案了 ...
- Jquery 时间格式化
var TimeObjectUtil;/** * @title 时间工具类 * @note 本类一律违规验证返回false * @author {boonyachengdu@gmail.com} * ...