笔记之android 动画1 用代码来实现动画

参考自大神博客:

http://blog.csdn.net/harvic880925/article/details/40117115

各个动画标签所对应的类

  • scale —— ScaleAnimation
  • alpha —— AlphaAnimation
  • rotate —— RotateAnimation
  • translate —— TranslateAnimation
  • set —— AnimationSet
Amination 是所有动画的基类


  • android:duration                  setDuration(long)  动画持续时间,以毫秒为单位 
  • android:fillAfter                    setFillAfter(boolean) 如果设置为true,控件动画结束时,将保持动画最后时的状态
  • android:fillBefore                 setFillBefore(boolean) 如果设置为true,控件动画结束时,还原到开始动画前的状态
  • android:fillEnabled              setFillEnabled(boolean) 与android:fillBefore 效果相同,都是在动画结束时,将控件还原到初始化状态
  • android:repeatCount           setRepeatCount(int) 重复次数
  • android:repeatMode            setRepeatMode(int) 重复类型,有reverse和restart两个值,取值为RESTART或 REVERSE,必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型,即回放时的动作。
  • android:interpolator            setInterpolator(Interpolator) 设定插值器,其实就是指定的动作效果,比如弹跳效果等
ScaleAnimation的几个构造函数:

  • ScaleAnimation(Context context, AttributeSet attrs)  从XML文件加载动画,基本用不到
  • ScaleAnimation(float fromX, float toX, float fromY, float toY)
  • ScaleAnimation(float fromX, float toX, float fromY, float toY, float pivotX, float pivotY)
  • ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
第一个构造方法是以控件左上角为中心进行伸缩

第二个构造方法是以控件的绝对偏移量为中心进行伸缩

第三个构造方法 的pivotXType 有三个类型 Animation.ABSOLUTE、Animation.RELATIVE_TO_SELF和Animation.RELATIVE_TO_PARENT

 Animation.ABSOLUTE:绝对值 如50 Animation.RELATIVE_TO_SELF 相对于自身 如 50% Animation.RELATIVE_TO_PARENT相对于父控件 50%p



AlphaAnimation的几个构造函数:

  • AlphaAnimation(Context context, AttributeSet attrs)  同样,从本地XML加载动画,基本不用
  • AlphaAnimation(float fromAlpha, float toAlpha)
  • RotateAnimation(Context context, AttributeSet attrs)  从本地XML文档加载动画,同样,基本不用
  • RotateAnimation(float fromDegrees, float toDegrees)
  • RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
  • RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
rotateAnimation2 = new RotateAnimation(0, 720, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
rotateAnimation2.setDuration(5000);
控件使用的时候
tv.startAnimation(rotateAnimation2);

TranslateAnimation 几个构造函数:

  • TranslateAnimation(Context context, AttributeSet attrs)  同样,基本不用
  • TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
  • TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)


AnimationSet 的构造函数:

  • AnimationSet(Context context, AttributeSet attrs)  同样,基本不用
  • AnimationSet(boolean shareInterpolator)  shareInterpolator取值true或false,取true时,指在AnimationSet中定义一个插值器(interpolater),它下面的所有动画共同。如果设为false,则表示它下面的动画自己定义各自的插值器。






rotateAnimation2 = new RotateAnimation(0, 720, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
rotateAnimation2.setDuration(5000);
控件使用的时候
tv.startAnimation(rotateAnimation2);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值