动画篇

Activity 转场动画  有一个函数: overridePendingTransition(R.anim.in_translate_top,  R.anim.out_translate_top); 第一个参数为进场动画,第二个是出场. Use 0 for no animation.  此外,必须紧跟在startActivity(Intent) or finish()后面调用

不过 更多使用 theme 的方法

<!-- 窗口进入和退出动画都有 -->
 <style name="ActivityInOutAnimation" parent="@android:style/Animation.Activity">
     <item name="android:activityOpenEnterAnimation">@anim/push_left_in</item>
     <item name="android:activityOpenExitAnimation">@anim/push_left_out</item>
     <item name="android:activityCloseEnterAnimation">@anim/push_right_in</item>
     <item name="android:activityCloseExitAnimation">@anim/push_right_out</item>
 </style>

open 系列的 item 是 A-->B  A的退场动画 和  B的 进场动画             进场都是 enter

close 系列的 item 是 B-->back  A的进场动画 和  B的 退场动画         退场都是 exit

 

view 动画 xml 的编辑文件存放于  res/drawable/anim

 

 public abstract class
Animation
extends Object
implements Cloneable
java.lang.Object
   ↳ 	android.view.animation.Animation
Known Direct Subclasses
<strong>AlphaAnimation, AnimationSet, RotateAnimation, ScaleAnimation, TranslateAnimation </strong>


由 view.animation 的继承结构可以看出 一共有 4种动画   : 透明度 的变化,  旋转动画,  缩放 动画  ,  位移动画  .  AnimationSet是  动画的组合

view.animation一般用 xml文件 配置:

Alpha:                           父类animation的属性

From classandroid.view.animation.Animation

   
                                                                                                                                                                                                                                                                                                                                                                                         
Attribute Name Related Method Description
android:detachWallpaper            setDetachWallpaper(boolean)                   Special option for window animations: if this window is on top  of a wallpaper, don't animate the wallpaper with it.  在壁纸上运行
android:duration            setDuration(long)                   Amount of time (in milliseconds) for the animation to run.  动画持续时间,毫秒为单位
android:fillAfter            setFillAfter(boolean)                   When set to true, the animation transformation is applied after the animation is  over. 控件动画结束时是否保持动画最后的状态
默认值是  false
android:fillBefore            setFillBefore(boolean)                   When set to true or when fillEnabled is not set to true, the animation transformation  is applied before the animation has started. 
默认值是   true
android:fillEnabled            setFillEnabled(boolean)                   When set to true, the value of fillBefore is taken into account. 
android:interpolator            setInterpolator(Interpolator)                   Defines the interpolator used to smooth the animation movement in time. 插值器
android:repeatCount            setRepeatCount(int)                   Defines how many times the animation should repeat.   重复次数  (结果是  n+1 次)
ConstantValueDescription
infinite-1
设置此值 可以 重复无限次
android:repeatMode            setRepeatMode(int)                   Defines the animation behavior when it reaches the end and the repeat count is             greater than 0 or infinite. 
ConstantValueDescription
restart1The animation starts again from the beginning.
reverse2The animation plays backward. 

android:startOffset            setStartOffset(long)                   Delay in milliseconds before the animation runs, once start time is reached. 
android:zAdjustment            setZAdjustment(int)                   Allows for an adjustment of the Z ordering of the content being             animated for the duration of the animation. 

 

android:fillAfter   android:fillBefore   android:fillEnabled (注意只能在该xml文件的 root tag上写这些属性,否则不会生效)  进行的测试结果  :  

filEnablefillBeforefillAfter结果结论
truetruetrue

最后一帧

 

 
 falsetrue

最后一帧

 

 
 falsefalse

第一帧

 

 
 truefalse

第一帧

 

 
falsetruetrue

最后一帧

 

 
 falsetrue

最后一帧

 

 
 falsefalse

第一帧

 

 
 truefalse第一帧

 

 


表一:SET属性
 

名称属性备注
android:shareInterpolator是否共享插入器共享时,四个子节点都用一个插入器
android:interpolator指定一个动画的插入器使用系统资源
android:fillEnabled
当设置为true时,fillAfter和fillBefroe将会都为true,此时会忽略fillBefore 和fillAfter两种属性
android:fillAfter该动画转化是否在动画结束后被应用boolean
android:fillBefore该动画转化是否在动画开始前被应用boolean
android:repeatMode重复模式"restart"  或者 "reverse"
android:repeatCount重复次数integer
android:duration动画持续时间integer
android:startOffset动画时间间隔long
android:zAdjustment定义动画z order的变换[normal] or [top] or [bottom]
android:detachWallpaper未知boolean
   
   

表二:alpha
名称属性备注
android:toAlpha动画结束时的透明度float [0,1]  0表示完全透明 1表示完全不透明
android:duration动画持续时间integer
android:fromAlpha动画开始时的透明度float [0,1]  0表示完全透明 1表示完全不透明
   


表三:SCALE
名称属性备注
android:fromXScale动画开始时,X坐标上的伸缩尺寸float,0.0表示收缩到没有、1.0表示正常无伸缩,小于1表示收缩,大于1表示放大
android:toXScale动画结束时,X坐标上的伸缩尺寸同上
android:fromYScale动画开始时,Y坐标上的伸缩尺寸同上
android:toYScale动画结束时,Y坐标上的伸缩尺寸同上
android:pivotX动画相对于物件的X的开始位置[0%,100%],50%表示中间
android:pivotY动画相对于物件的Y的开始位置0%,100%],50%表示中间
android:duration同set同set
   

表四:TRANSLATE
名称属性备注
android:fromXDelta动画开始时,X坐标上的位置integer  默认以自己为参照物
android:toXDelta动画结束时,X坐标上的位置integer  默认以自己为参照物
android:fromYDelta动画开始时,Y坐标上的位置integer  默认以自己为参照物
android:toYDelta动画结束时,Y坐标上的位置integer  默认以自己为参照物
   

表五:ROTATE
名称属性备注
android:fromDegrees动画开始时,物件的角度负数:逆时针旋转,正数:顺时针旋转
android:toDegrees动画结束时,物件的角度(可大于360度)同上
android:pivotX动画相对于物件的X的开始位置[0%,100%],50%表示中间
android:pivotY动画相对于物件的Y的开始位置[0%,100%],50%表示中间
   

---注意---android:pivotX的值共有三种设置方法:

1. android:pivotX="50"这种方法使用自身定位           (控件左上角  为坐标原点)

2. android:pivotX="50%"这种方法相对于控件本身定位  ( 100% 代表 控件的 一个 宽度)

3. android:pivotX="50%p"这种方法相对于控件的父控件定位

android:fromXDelta  android:toXDelta   也是 这个 用法  . 

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   为例

xValue   和 xType     其实就是  xXDelta 的分开写法      xtype的 取值 有 3个常量   RELATIVE_TO_SELF, RELATIVE_TO_PARENT,ABSOLUTE

踩用 相对 形式时   xValue 的取值   以 小数形式写  :  1.0-->100%;       绝对模式下直接写数值


补间动画 的  用法   :   在代码中直接  new 一个然后设置状态,  或者用    AnimationUtils.loadAnimation  加载一个xml动画






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值