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动画是操作某个控件让其展现出旋转.渐变.移动.缩放的这么一种 ...
随机推荐
- SE 2014年3月31日
一. 描述OSPF划分区域的优势. OSPF划分区域的优势主要表现在以下几个方面: 1. 当网络中路由器的数量增大时,划分区域有利于减轻一部分性能较低的设备的处理和维护LSA数据库. 2. 区域的划分 ...
- gdb学习(一个)[再版]
概要 gdb是GNU debugger的缩写,是编程调试工具. 功能 1.启动程序,能够依照用户自己定义的要求随心所欲的执行程序. 2.可让被调试的程序在用户所指定的断点处停住 (断点能够是条件表达式 ...
- c#代码规范和质量检查工具这点事
c#代码规范和质量检查工具这点事 代码风格检查:StyleCop 代码缺陷检查:FxCop 代码质量: 代码度量值/Code Metrics StyleCop 介绍 The StyleCop tool ...
- linq 中执行方法
Database1Entities db = new Database1Entities(); protected void Page_Load(object sender, EventArgs e) ...
- WPF如何获得变量异步回调函数时产生的异步回调
有这样的问题,WPF当使用异步回调,需要使用产生的异步变量中的回调函数.数据库中查询诸如异步函数来获得一DataTable.怎样传递给回调函数呢? [方案一]使用全局变量 非常easy想到的是用全局变 ...
- ECLIPSE JSP TOMCAT 环境搭建
ECLIPSE JSP TOMCAT 环境搭建(完整) 要学习一门语言,首先要做的就是搭建环境,然后能写一个小的Demo(类似Helloworld),不仅可以建立信心,而且还可以为之后的学习搭建一个验 ...
- 普通的年轻状态机,纯C语言
我们第一次接触到了状态机.在数字电路课程.计数器.串行奇偶校验.考了1连续报错电路 等待,两者都需要一个状态机模型.电路实现这些功能,与状态机的状态转移图.状态转移表是等价. 后.然后,我们联系了状态 ...
- 使用jni技术进行android应用签名信息核查及敏感信息保护
近期业余时间写了一款应用<摇啊摇>,安智.安卓.360等几个应用商店已经陆续审核通过并上线.从有想法到终于将产品做出来并公布,断断续续花了近二个半月的业余时间,整体来讲还算顺 ...
- simplePagination API
simplePagination API simplePagination.js 一个简单的jQuery分页插件,主题和Bootstrap支持CSS 3 分页button样式 "light- ...
- swift笔记 (三) —— 字符和字符串
字符串和字符 苹果要是不提供了unicode的字符串和字符,那就是他们公司全部人的脑袋都被门夹过 他自己家都要发非常多国家的版本号的软件,怎么可能不用unicode呢 此处略去30字... 这里能够拿 ...