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);

动画效果如下图:
Android平移动画_第1张图片

其它就不一一举例了

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

/*** 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等等,就不举例了

更多相关文章

  1. android中软件参数保存
  2. JS判断终端类型的几种方法
  3. Android非UI线程访问UI线程的方法总结
  4. android Property Animation 属性动画详解
  5. android image加载中等待动画

随机推荐

  1. Android应用程序键盘(Keyboard)消息处理机
  2. Android入门教程(四)之------Android工程
  3. Android(安卓)小项目之--SQLite 使用法门
  4. Android(安卓)9 (P)系统启动之SystemServ
  5. Android面试系列文章2018之Android部分事
  6. libacc : Android(安卓)2.0 內建的輕量級
  7. Android(安卓)轻松实现语音识别的完整代
  8. Android开发工程师 iOS开发工程师正在招
  9. android体系结构
  10. 浅谈android的selector,背景选择器