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动画是操作某个控件让其展现出旋转.渐变.移动.缩放的这么一种 ...
随机推荐
- linux+nginx+mysql+php
LNMP(linux+nginx+mysql+php)服务器环境配置 一.简介 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为 “engine X”, 是一个高性能的 ...
- Android Fragment使用
通常地 fragment做为宿主activity UI的一部分, 被作为activity整个view hierarchy的一部分被嵌入. 有2种方法你能够加入一个fr ...
- 如何让HTML在手机上实现直接拨打电话以及发送短信?
拨打电话的HTML实现方式: <a href="tel:134289210xx″>拨打电话</a> 上面是比较常用的方式,但是有可能在某些场景下是支持不太好,可以试用 ...
- ECshop lib_base.php on line 1241 错误解决方法
ECSHOP做的一个网站,突然报这个错误,整个网站打不开,后来找了很久,终于找到这个方法,亲测可用 Notice: Undefinedvariable: data in D:\wwwroot\KISS ...
- WPF如何获得变量异步回调函数时产生的异步回调
有这样的问题,WPF当使用异步回调,需要使用产生的异步变量中的回调函数.数据库中查询诸如异步函数来获得一DataTable.怎样传递给回调函数呢? [方案一]使用全局变量 非常easy想到的是用全局变 ...
- Oracle SQL Lesson (1) - 使用SQL Select语句获取数据
第一节课: 启动数据库并且使用特定用户连接:su - oracle; 启动sqlplus并且使用sys连接:conn / as sysdba; 启动数据库:startup; 解锁用户:alter us ...
- QVector<QString> 显示器里面的动态数组元素QString和char *转变
QVector类是一类提供了动态数组模板. QVector<T>是Qt普通容器类的一种. 它将自己的每个对象存储在连续的内存中.能够使用索引號来高速訪问它们.QList<T>. ...
- php laravel 帧 该文件上传
好,我承认我的忠告. 今天laravel框架编写一个文件上传部分.总能找到不正确的路径.但是,终于攻克. 以下我分享一下自己的学习体会吧. client <form method="P ...
- 动画(Animation) 它 (闪烁、左右摇摆、跷跷板等功效)
一侧到另一侧的影响: (这里显示的是并不那么顺利) 一.续播 (不知道取什么名字好,就是先播放动画A, 接着播放动画B) 有两种方式. 第一种.分别动画两个动画,A和B, 然后先播放动画A,设置A ...
- Android定位功能(二)
在前文Android定位功能(一)中,已经大致介绍了一下在Android平台中,和定位功能相关的类,并举例获取了位置信息.但是前文是基于Criteria定制了一个标准,通过getBestProvide ...