Android平移动画

核心方法

public void startAnimation(Animation animation)
执行动画,参数可以是各种动画的对象,Animation的多态,也可以是组合动画,后面会有。

平移动画的构造方法

public TranslateAnimation(Context context, AttributeSet attrs)
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

第二个构造方法的官方注释说明

/**
* Constructor to use when building a TranslateAnimation from code
*
* @param fromXDelta Change in X coordinate to apply at the start of the animation
* @param toXDelta Change in X coordinate to apply at the end of the animation
* @param fromYDelta Change in Y coordinate to apply at the start of the animation
* @param toYDelta Change in Y coordinate to apply at the end of the animation
*/
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
  • 首先被移动对象是有一个初始坐标的,下面的参数都是基于这个原点。
  • 第一个参数是动画的 X轴 起始坐标 相对于 原点 的位置
  • 第二个参数是动画的 X轴 停止坐标 相对于 原点 的位置
  • 第三个参数是动画的 Y轴 起始坐标 相对于 原点 的位置
  • 第四个参数是动画的 Y轴 停止坐标 相对于 原点 的位置

举例:

TranslateAnimation ta = new TranslateAnimation(-200,100,0,0);
// 设置动画播放的时间
ta.setDuration(3000);
// 设置动画重复播放的次数
ta.setRepeatCount(1);
// 设置动画重复播放的模式
ta.setRepeatMode(TranslateAnimation.REVERSE);
// 开始播放动画
iv.startAnimation(ta);

动画效果如下图:

其它就不一一举例了

第三个构造方法的官方注释说明

/**
* Constructor to use when building a TranslateAnimation from code
*
* @param fromXType Specifies how fromXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param fromXValue Change in X coordinate to apply at the start of the animation. This value can either be an absolute number if fromXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
* @param toXType Specifies how toXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param toXValue Change in X coordinate to apply at the end of the animation. This value can either be an absolute number if toXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
* @param fromYType Specifies how fromYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param fromYValue Change in Y coordinate to apply at the start of the animation. This value can either be an absolute number if fromYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
* @param toYType Specifies how toYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param toYValue Change in Y coordinate to apply at the end of the animation. This value can either be an absolute number if toYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
*/
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

其实这里的第2、4、6、8个参数就是对应上面四个参数构造里的第1、2、3、4个参数,这里的第1、3、5、7个参数分别是第2、4、6、8个参数的类型,上面的是默认都给设置成了“ABSOLUTE”类型,这里还可以设置RELATIVE_TO_SELF和RELATIVE_TO_PARENT等等,就不举例了

Android平移动画的更多相关文章

  1. Android动画:模拟开关按钮点击打开动画(属性动画之平移动画)

    在Android里面,一些炫酷的动画确实是很吸引人的地方,让然看了就赏心悦目,一个好看的动画可能会提高用户对软件的使用率.另外说到动画,在Android里面支持3种动画: 逐帧动画(Frame Ani ...

  2. Android 手机卫士--平移动画实现

    本文实现如下几个界面之间的平移动画实现 本文地址:http://www.cnblogs.com/wuyudong/p/5954847.html,转载请注明出处. 分析: 导航界面移动过程中,平移动画 ...

  3. android 帧动画,补间动画,属性动画的简单总结

      帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...

  4. Android属性动画之ObjectAnimator

    相信对于Android初学者,对于Android中的动画效果一定很感兴趣,今天为大家总结一下刚刚学到的属性动画案例. 首先和一般的Android应用一样,我们先建一个工程,为了方便,我们的布局文件中就 ...

  5. 79.Android之动画基础

    转载:http://a.codekk.com/detail/Android/lightSky/%E5%85%AC%E5%85%B1%E6%8A%80%E6%9C%AF%E7%82%B9%E4%B9%8 ...

  6. Android属性动画完全解析(上),初识属性动画的基本用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系 ...

  7. Android属性动画完全解析(中)

    转载:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是 ...

  8. Android属性动画完全解析(上)

    Android属性动画完全解析(上) 转载:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷 ...

  9. android 属性动画

    一直再追郭霖的博客和imooc上的一些新的视频,最近有讲到属性动画. 以下内容为博客学习以及imooc上视频资料的学习笔记: 在3.0之前比较常见的动画为tween动画和frame动画: tween动 ...

随机推荐

  1. [Codeforces]848C - Goodbye Souvenir

    题目大意:n个数字,m次操作,支持修改一个数字和查询一个区间内每种数字最大出现位置减最小出现位置的和.(n,m<=100,000) 做法:把每个数字表示成二维平面上的点,第一维是在数组中的位置, ...

  2. NOIP2014-10-30模拟赛

    T1:逗比三角形 [题目描述] 小J是一名OI退役滚粗文化课选手,他十分喜欢做题,尤其是裸题.他现在有一个二维盒子和一些二维三角形,这个盒子拥有无限的高度和L的宽度.而且他的三角形也都是一些锐角三角形 ...

  3. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  4. VS2012不能加载想要打开的项目/解决方案

    今天回宿舍用自己的电脑敲代码,想要打开之前的项目,可是VS2012打开之后项目却显示“无法加载” 查了之后才知道原来是由于某个安装包缺少引起的,具体做法请看如下 链接:http://jingyan.b ...

  5. MySQL创建用户与授权(CentOS6.5)

    1.相关SQL语句 #创建用户与授权方法 ##本地访问 create user 'zend'@'localhost' IDENTIFIED BY '123456'; grant ALL privile ...

  6. struts2 可以用ognl拿到值而不可以用el拿到值的解决方法

    错误debug后 得到了There is no read method for container的错误 于是我new了一个实体类 package com.unity; public class St ...

  7. 阿里架构师带你深入浅出jvm

    本文跟大家聊聊JVM的内部结构,从组件中的多线程处理,JVM系统线程,局部变量数组等方面进行解析 JVM JVM = 类加载器(classloader) + 执行引擎(execution engine ...

  8. CentOS6.8虚拟机安装及ORALCE安装记录

    CENTOS6.8安装数据库及设置自启动脚本教程 作者:张欣橙 本文所需要的所有参数均位于文末附录中 一.新建虚拟机 选择下一步 选择下一步 选择稍后安装操作系统 选择LINUX 版本 CentOS ...

  9. JAVA 练习 找出素数

    package com.zhang.hello; public class Task { /** * 1. 输出打印九九乘法表 * */ public void NO1(){ for(int i=1; ...

  10. python的IDE(pycharm)安装以及简单配置

    使用IDE的好处 界面更友好,看起来更舒服 智能提示功能很赞,大大提高开发效率 pycharm的安装过程 去pycharm官网下载安装包,请下载专业版,建议不要去网上下载汉化版 点击安装包一直下一步即 ...