• android.view.animation(1)


    一.ScaleAnimation

    ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

    • android:fromXScale    起始的X方向上相对自身的缩放比例,浮点值,比如1.0代表自身无变化,0.5代表起始时缩小一倍,2.0代表放大一倍;
    • android:toXScale        结尾的X方向上相对自身的缩放比例,浮点值;
    • android:fromYScale    起始的Y方向上相对自身的缩放比例,浮点值,
    • android:toYScale        结尾的Y方向上相对自身的缩放比例,浮点值;
    • android:pivotX            缩放起点X轴坐标,可以是数值、百分数、百分数p 三种样式,比如 50、50%、50%p,当为数值时,表示在当前View的左上角,即原点处加上50px,做为起始缩放点;如果是50%,表示在当前控件的左上角加上自己宽度的50%做为起始点;   如果是50%p,那么就是表示在当前的左上角加上父控件宽度的50%做为起始点x轴坐标。(具体意义,后面会举例演示)
    • android:pivotY           缩放起点Y轴坐标,取值及意义跟android:pivotX一样。
    <?xml version="1.0" encoding="utf-8"?>  
    <scale xmlns:android="http://schemas.android.com/apk/res/android"  
        android:fromXScale="0.0"  
        android:toXScale="1.4"  
        android:fromYScale="0.0"  
        android:toYScale="1.4"  
        android:pivotX="50"  
        android:pivotY="50"  
        android:duration="700" />  

    (1)、pivotX取值数值时(50)

    这个控件,宽度和高度都是从0放大到1.4倍,起始点坐标在控件左上角(坐标原点),向x轴正方向和y轴正方向都加上50像素;

    根据pivotX,pivotY的意义,控件的左上角即为控件的坐标原点,这里的起始点是在控件的原点的基础上向X轴和Y轴各加上50px,做为起始点,如下图中图二所示

     

    (2)、pivotX取值百分数时(50%)
    下面再看看当pivotX、pivotY取百分数的时候,起始点又在哪里?
    上面我们讲了,pivotX的值,当取50%时,表示在原点坐标的基础上加上的自己宽度的50%,看看效果:

    <?xml version="1.0" encoding="utf-8"?>  
    <scale xmlns:android="http://schemas.android.com/apk/res/android"  
        android:fromXScale="0.0"  
        android:toXScale="1.4"  
        android:fromYScale="0.0"  
        android:toYScale="1.4"  
        android:pivotX="50%"  
        android:pivotY="50%"  
        android:duration="700" />  

     

    (3)、pivotX取值50%p时
    前面说过,当取值在百分数后面加上一个字母p,就表示,取值的基数是父控件,即在原点的基础上增加的值是父标签的百分值。

    <?xml version="1.0" encoding="utf-8"?>  
    <scale xmlns:android="http://schemas.android.com/apk/res/android"  
        android:fromXScale="0.0"  
        android:toXScale="1.4"  
        android:fromYScale="0.0"  
        android:toYScale="1.4"  
        android:pivotX="50%p"  
        android:pivotY="50%p"  
        android:duration="700" />  

    二.Animation

    Animation类是所有动画(scale、alpha、translate、rotate)的基类,这里以scale标签为例,讲解一下,Animation类所具有的属性及意义。

    • android:duration        动画持续时间,以毫秒为单位 
    • android:fillAfter          如果设置为true,控件动画结束时,将保持动画最后时的状态
    • android:fillBefore       如果设置为true,控件动画结束时,还原到开始动画前的状态
    • android:fillEnabled    与android:fillBefore 效果相同,都是在动画结束时,将控件还原到初始化状态
    • android:repeatCount 重复次数
    • android:repeatMode 重复类型,有reverse和restart两个值,reverse表示倒序回放,restart表示重新放一遍,必须与repeatCount一起使用才能看到效果。因为这里的意义是重复的类型,即回放时的动作。
    • android:interpolator  设定插值器,其实就是指定的动作效果,比如弹跳效果等,不在这小节中讲解,后面会单独列出一单讲解。

    对于android:duration,就不再讲解了,就是动画的持续时长,以毫秒为单位,下面看看android:fillAfter和android:fillBefore

    三.AlphaAnimation

    AlphaAnimation(float fromAlpha, float toAlpha)

    • android:fromAlpha   动画开始的透明度,从0.0 --1.0 ,0.0表示全透明,1.0表示完全不透明
    • android:toAlpha       动画结束时的透明度,也是从0.0 --1.0 ,0.0表示全透明,1.0表示完全不透明
    <?xml version="1.0" encoding="utf-8"?>  
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"  
        android:fromAlpha="1.0"  
        android:toAlpha="0.1"  
        android:duration="3000"  
        android:fillBefore="true">  
    </alpha> 

    四.RotateAnimation

    RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

    • android:fromDegrees     开始旋转的角度位置,正值代表顺时针方向度数,负值代码逆时针方向度数
    • android:toDegrees         结束时旋转到的角度位置,正值代表顺时针方向度数,负值代码逆时针方向度数
    • android:pivotX               缩放起点X轴坐标,可以是数值、百分数、百分数p 三种样式,比如 50、50%、50%p,具体意义已在scale标签中讲述,这里就不再重讲
    • android:pivotY               缩放起点Y轴坐标,可以是数值、百分数、百分数p 三种样式,比如 50、50%、50%p
    <?xml version="1.0" encoding="utf-8"?>  
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"  
        android:fromDegrees="0"  
        android:toDegrees="650"  
        android:pivotX="50%"  
        android:pivotY="50%"  
        android:duration="3000"  
        android:fillAfter="true">  
          
    </rotate>  

    围绕自身从0度顺时针旋转650度

     android:fromDegrees="0"

     android:toDegrees="650"

    五.TranslateAnimation

    TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

    • android:fromXDelta     起始点X轴坐标,可以是数值、百分数、百分数p 三种样式,比如 50、50%、50%p,具体意义已在scale标签中讲述,这里就不再重讲
    • android:fromYDelta    起始点Y轴从标,可以是数值、百分数、百分数p 三种样式;
    • android:toXDelta         结束点X轴坐标
    • android:toYDelta        结束点Y轴坐标
    <?xml version="1.0" encoding="utf-8"?>  
    <translate xmlns:android="http://schemas.android.com/apk/res/android"  
        android:fromXDelta="0"   
        android:toXDelta="-80"  
        android:fromYDelta="0"  
        android:toYDelta="-80"  
        android:duration="2000"  
        android:fillBefore="true">  
    </translate>  

    六.AnimationSet

    AnimationSet(boolean shareInterpolator)

    如果参数为true,则代表该AnimationSet中的所有元素都使用AnimationSet关联的Interpolator。反之,则使用各自关联的Interpolator。

    <?xml version="1.0" encoding="utf-8"?>  
    <set xmlns:android="http://schemas.android.com/apk/res/android"  
        android:duration="3000"  
        android:fillAfter="true">  
          
      <alpha   
        android:fromAlpha="0.0"  
        android:toAlpha="1.0"/>  
        
      <scale  
        android:fromXScale="0.0"  
        android:toXScale="1.4"  
        android:fromYScale="0.0"  
        android:toYScale="1.4"  
        android:pivotX="50%"  
        android:pivotY="50%"/>  
        
      <rotate  
        android:fromDegrees="0"  
        android:toDegrees="720"  
        android:pivotX="50%"  
        android:pivotY="50%"/>  
             
    </set>  

    参考链接:

    自定义控件三部曲之动画篇(一)——alpha、scale、translate、rotate、set的xml属性及用法

  • 相关阅读:
    PAT乙级1008. 数组元素循环右移问题 (20)
    PAT乙级1007. 素数对猜想 (20)
    PAT乙级1006. 换个格式输出整数 (15)
    ubuntu mate 开机自动启动ssh服务
    ubuntu 修改网卡名称
    ubuntu 绑定固定ip
    ubuntu sogou 輸入法無法輸入文字,解決辦法【转载】
    select()函数小结【转载】
    listen函数小结
    python学习过程二(《python核心编程》第三章)
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/7903233.html
Copyright © 2020-2023  润新知