• 补间动画(TweenAnimation)

* 原形态变成新形态时为了过渡变形过程,生成的动画就叫补间动画(为了让对象从初始状态向结束状态改变的过程更加自然而自动生成的动画效果)
* 位移、旋转、缩放、透明

1、位移

* 参数10指的是X的起点坐标,但不是指屏幕x坐标为10的位置,而是imageview的 真实X + 10
* 参数150指的是X的终点坐标,它的值是imageview的 真实X + 150

TranslateAnimation ta = new TranslateAnimation(-100, 100, -60, 60);
* -100:表示动画的水平方向的初始坐标
* iv原始x -100
* 100:表示动画的水平方向的结束坐标
* iv的原始x + 100

TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.5f, Animation.RELATIVE_TO_SELF, 1.5f, Animation.RELATIVE_TO_SELF, -2, Animation.RELATIVE_TO_SELF, 2);
* -1.5f:表示动画的水平方向的初始坐标
* iv的原始x - iv宽度 * 1.5
* 1.5f:表示动画的水平方向的结束坐标
* iv的原始x + iv宽度 * 1.5

//创建为位移动画对象,设置动画的初始位置和结束位置
TranslateAnimation ta = new TranslateAnimation(10, 150, 20, 140);
* x坐标的起点位置,如果相对于自己,传0.5f,那么起点坐标就是 真实X + 0.5 * iv宽度
* x坐标的终点位置,如果传入2,那么终点坐标就是 真实X + 2 * iv的宽度
* y坐标的起点位置,如果传入0.5f,那么起点坐标就是 真实Y + 0.5 * iv高度
* y坐标的终点位置,如果传入2,那么终点坐标就是 真实Y + 2 * iv高度

TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2);

* 动画播放相关的设置

//设置动画持续时间
ta.setDuration(2000);
//动画重复播放的次数
ta.setRepeatCount(1);
//动画重复播放的模式
ta.setRepeatMode(Animation.REVERSE);
//动画播放完毕后,组件停留在动画结束的位置上
ta.setFillAfter(true);
//播放动画
iv.startAnimation(ta);

package com.itheima.tweenanimation;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView; public class MainActivity extends Activity { private ImageView iv;
private TranslateAnimation ta;
private ScaleAnimation sa;
private AlphaAnimation aa;
private RotateAnimation ra; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv);
} public void translate(View v){
//定义位移补间动画
// TranslateAnimation ta = new TranslateAnimation(-100, 100, -60, 60); ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.5f, Animation.RELATIVE_TO_SELF, 1.5f,
Animation.RELATIVE_TO_SELF, -2, Animation.RELATIVE_TO_SELF, 2);
//定义动画持续时间
ta.setDuration(2000);
//设置重复次数
ta.setRepeatCount(1);
//设置重复模式
ta.setRepeatMode(Animation.REVERSE);
//在结束位置上填充动画
ta.setFillAfter(true);
//播放动画
iv.startAnimation(ta); } public void scale(View v){
// ScaleAnimation sa = new ScaleAnimation(0.2f, 2, 0.2f, 2);
// ScaleAnimation sa = new ScaleAnimation(0.2f, 2, 0.2f, 2, iv.getWidth()/2, iv.getHeight()/2); sa = new ScaleAnimation(0.3f, 2, 0.2f, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//定义动画持续时间
sa.setDuration(2000);
//设置重复次数
sa.setRepeatCount(1);
//设置重复模式
sa.setRepeatMode(Animation.REVERSE);
//在结束位置上填充动画
sa.setFillAfter(true);
//播放动画
iv.startAnimation(sa);
} public void alpha(View v){
aa = new AlphaAnimation(1, 0.2f);
aa.setDuration(2000);
aa.setRepeatCount(1);
aa.setRepeatMode(Animation.REVERSE);
aa.setFillAfter(true);
iv.startAnimation(aa);
} public void rotate(View v){
// RotateAnimation ra = new RotateAnimation(0, 720);
// RotateAnimation ra = new RotateAnimation(0, 720, iv.getWidth()/2, iv.getHeight()/2); ra = new RotateAnimation(0, -720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); ra.setDuration(2000);
ra.setRepeatCount(1);
ra.setRepeatMode(Animation.REVERSE);
ra.setFillAfter(true);
iv.startAnimation(ra);
} public void fly(View v){
//创建动画集合
AnimationSet set = new AnimationSet(false);
//把动画添加至集合
set.addAnimation(ta);
set.addAnimation(sa);
set.addAnimation(aa);
set.addAnimation(ra); //开始播放集合
iv.startAnimation(set);
} }

MainActivity

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="位移"
android:onClick="translate"
/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="缩放"
android:onClick="scale"
/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="透明"
android:onClick="alpha"
/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="旋转"
android:onClick="rotate"
/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="一起飞"
android:onClick="fly"
/>
</LinearLayout>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_centerInParent="true"
/> </RelativeLayout>

activity_main

2、缩放

* 参数0.1f表示动画的起始宽度是真实宽度的0.1倍
* 参数4表示动画的结束宽度是真实宽度的4倍
* 缩放的中心点在iv左上角

ScaleAnimation sa = new ScaleAnimation(0.3f, 2, 0.2f, 1, iv.getWidth()/2, iv.getHeight()/2);
* 0.3f:动画x轴的初始比例
* 2:动画x轴的结束比例
* iv.getWidth()/2:缩放点的x坐标
* iv原始x + iv.getWidth()/2

ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4);
* 参数0.1f和4意义与上面相同
* 改变缩放的中心点:传入的两个0.5f,类型都是相对于自己,这两个参数改变了缩放的中心点
* 中心点x坐标 = 真实X + 0.5 * iv宽度
* 中心点Y坐标 = 真实Y + 0.5 * iv高度

ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
3、透明

AlphaAnimation aa = new AlphaAnimation(1, 0.2f);
* 1:动画的初始透明度
* 0.2f:动画结束透明度

* 0为完全透明,1为完全不透明

AlphaAnimation aa = new AlphaAnimation(0, 0.5f);

4、旋转

ra = new RotateAnimation(0, -720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
* 0:动画的初始角度
* 720:动画的结束角度
* Animation.RELATIVE_TO_SELF, 0.5f:旋转的中心点坐标:
* iv的原始x + iv宽度 * 0.5

* 20表示动画开始时的iv的角度
* 360表示动画结束时iv的角度
* 默认旋转的圆心在iv左上角

RotateAnimation ra = new RotateAnimation(20, 360);
* 20,360的意义和上面一样
* 指定圆心坐标,相对于自己,值传入0.5,那么圆心的x坐标:真实X + iv宽度 * 0.5
* 圆心的Y坐标:真实Y + iv高度 * 0.5

RotateAnimation ra = new RotateAnimation(20, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
5、所有动画一起飞

//创建动画集合
AnimationSet set = new AnimationSet(false);
//往集合中添加动画
set.addAnimation(aa);
set.addAnimation(sa);
set.addAnimation(ra);
iv.startAnimation(set);

android 学习随笔二十五(动画:补间动画)的更多相关文章

  1. android 学习随笔二十六(动画:属性动画)

    属性动画,属性动画是真正改变对象的某个属性的值 * 补间动画,只是一个动画效果,组件其实还在原来的位置上,xy没有改变1.位移:* 第一个参数target指定要显示动画的组件* 第二个参数proper ...

  2. android 学习随笔二十四(动画:帧动画)

    帧动画,一张张图片不断的切换,形成动画效果 * 在drawable目录下定义xml文件,子节点为animation-list,在这里定义要显示的图片和每张图片的显示时长 * FrameAnimatio ...

  3. android 学习随笔二十二(小结)

    ADB进程 * adb指令 * adb install xxx.apk * adb uninstall 包名 * adb devices * adb start-server * adb kill-s ...

  4. android 学习随笔二十(多媒体编程 )

    1.图片处理 加载大图片 图片大小的计算 图片大小 = 图片的总像素 * 每个像素占用的大小 * 单色图:每个像素占用1/8个字节* 16色图:每个像素占用1/2个字节* 256色图:每个像素占用1个 ...

  5. android 学习随笔二十九(自定义监听 )

    package com.itheima.momo.dialog; import com.itheima.momo.R; import android.app.AlertDialog; import a ...

  6. android 学习随笔二十八(应用小知识点小结 )

    去掉标题栏的方法 第一种:也一般入门的时候经常使用的一种方法requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏注意这句一定要写在setConte ...

  7. python3.4学习笔记(二十五) Python 调用mysql redis实例代码

    python3.4学习笔记(二十五) Python 调用mysql redis实例代码 #coding: utf-8 __author__ = 'zdz8207' #python2.7 import ...

  8. 学习笔记:CentOS7学习之二十五:shell中色彩处理和awk使用技巧

    目录 学习笔记:CentOS7学习之二十五:shell中色彩处理和awk使用技巧 25.1 Shell中的色彩处理 25.2 awk基本应用 25.2.1 概念 25.2.2实例演示 25.3 awk ...

  9. Android笔记(六十四) android中的动画——补间动画(tweened animation)

    补间动画就是只需要定义动画开始和结束的位置,动画中间的变化由系统去补齐. 补间动画由一下四种方式: 1.AplhaAnimation——透明度动画效果 2.ScaleAnimation ——缩放动画效 ...

随机推荐

  1. C#实现二叉查找树

    简介 树是一种非线性结构.树的本质是将一些节点由边连接起来,形成层级的结构.而二叉树是一种特殊的树,使得树每个子节点必须小于等于2.而二叉查找树又是一类特殊的二叉树.使得每一个节点的左节点或左子树的所 ...

  2. :first与:first-child的区别

    说的简单,:first表示单个元素,:fisrt-child表示的多个元素(集合). 如果追求深一点的话, 1.$(:first).css()表示全局或局部全局的第一个,也就是表示单个元素 2.$(: ...

  3. 数据库字段Pointer的操作方法

    多数情况下要要是Pointer字段实现了类似传统关系数据库的关联操作,联合查询能够减少提交次数,今天带来几种过滤器的使用方法: 首先确定2个Class,也就是表: A表:user表,用户个人信息,字段 ...

  4. SQLServer 统计数据量

    做一个项目,第一件事情就是问:“这个数据库多大?” 下面是统计数据库数据量大小的方法 通常我们会使用命令: "sp_helpdb @dbname" 例如,查询数据库"te ...

  5. 零售业数据分析的媒介——BI工具

    当你需要从一堆复杂庞大的数据中分析出有用的信息和结论的时,想必你一定觉得力不从心:数据的冗余使得你分析起来困难重重,怎么办呢?今天我们就来讲一下使数据分析变得简单有效的“手段”. 对于当今的中国零售行 ...

  6. IIS URL Rewrite redirect from one Domain to another

    IIS URL Rewrite enables Web administrators to create powerful rules to implement URLs that are easie ...

  7. 对ASP.NET Cookie的一些新的认识

    做用户登录,我一直用form验证的方式.有时候,为了节省时间,用户希望用户名输入框能够记住用户名,省得下次重新输入.这个时候光用form验证是不行的,因为form验证的话,用户一退出系统就失效了,所以 ...

  8. c# 排序算法总结

    /// <summary> /// 冒泡排序法1 /// </summary> /// <param name="list"></para ...

  9. (Command Pattern)命令模式

    定义 将“请求”封装成对象,以便使用不同的请求.队列或者日志来参数化其他对象.命令模式也支持可撤销的操作. 结构图: 命令模式的角色划分: Reciever(命令的接收者):接收命令,并知道如何进行必 ...

  10. 为什么要在block用weak self

    block会给内部所有的对象引用计数加一,这一方面会带来潜在的retain cycle,不过我们可以通过Weak Self的手段解决.另一方面比较重要就是,它会延长对象的生命周期. 在block前面写 ...