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. HDU 5412 CRB and Queries 动态整体二分

    Problem Description There are N boys in CodeLand.Boy i has his coding skill Ai.CRB wants to know who ...

  2. 【Uva 11280 飞到弗雷德里顿】

    ·你可以尽情地坐飞机,但停留次数遭到限制. ·英文题,述大意:       给出一张有向图,起点是输入的第一个城市,终点是输入的最后一个城市.给出q个询问,每个询问含一个t,表示 #include&l ...

  3. Android Studio创建/打开项目时一直处于Building“project name”Gradle project info的解决办法

    重新安装了Android studio 之后, 启动android studio,打开原来的项目,界面一直停留在: 一直停留在此界面的原因是:Android studio 在下载 Gradle ,但是 ...

  4. 环境变量方式使用 Secret - 每天5分钟玩转 Docker 容器技术(158)

    通过 Volume 使用 Secret,容器必须从文件读取数据,会稍显麻烦,Kubernetes 还支持通过环境变量使用 Secret. Pod 配置文件示例如下: 创建 Pod 并读取 Secret ...

  5. C语言程序设计第一次实验

    一. 1.输入圆的半径,计算圆的面积周长问题 2流程图 3测试数据及运算结果 4实验分析 不会输入r,后来问了同学得到解决. 二. 1.输入一个四位年份,判断其是否是闰年.闰年的判别条件是概念年份能被 ...

  6. c语言第六次作业v

    (一)改错题 序列求和:输入一个正实数eps,计算序列部分和 1 - 1/4 + 1/7 - 1/10 + ... ,精确到最后一项的绝对值小于eps(保留6位小数). 输入输出样例: Input e ...

  7. jvm 指令集代码

    指令码 助记符 说明 0x00 nop 什么都不做 0x01 aconst_null 将null推送至栈顶 0x02 iconst_m1 将int型-1推送至栈顶 0x03 iconst_0 将int ...

  8. Ambari2.6.0 安装HDP2.6.3(离线安装)

    一.下载安装包 因为使用在线安装特别慢,所有的安装包加起来有9个G左右,所以本教程是通过迅雷下载包,然后上传到服务器,通过配置本地源的方式来实现的离线安装.通过ambari安装需要下载下面的三个主要包 ...

  9. 如何在Eclipse中快速添加main方法

    在创建类时自动添加,只需要勾选"public static void main(String[]   args)"

  10. 罗列Linux发行版的基础目录名称,命令法则和功能

    罗列Linux发行版的基础目录名称命名法则及功用规定 目录描述 /主层次 的根,也是整个文件系统层次结构的根目录 /bin存放在单用户模式可用的必要命令二进制文件,所有用户都可用,如 cat.ls.c ...