ScaleAnimation动画

来源:互联网 发布:安卓鼓机软件 编辑:程序博客网 时间:2024/05/01 13:48
ScaleAnimation动画是用来进行缩放的动画,我在使用时刚开始有些不解的问题
后来经过学习,有了一个更深的了解。
先来看看源码,其实ScaleAnimation有四个构造函数,这里我只列出了其中的一个,因为
另外的三个其实都只是这个构造函数的一种特殊情况,这里我就只分析这个构造函数。

 /**     * Constructor to use when building a ScaleAnimation from code     *      * @param fromX Horizontal scaling factor to apply at the start of the     *        animation     * @param toX Horizontal scaling factor to apply at the end of the animation     * @param fromY Vertical scaling factor to apply at the start of the     *        animation     * @param toY Vertical scaling factor to apply at the end of the animation     * @param pivotXType Specifies how pivotXValue should be interpreted. One of     *        Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or     *        Animation.RELATIVE_TO_PARENT.     * @param pivotXValue The X coordinate of the point about which the object     *        is being scaled, specified as an absolute number where 0 is the     *        left edge. (This point remains fixed while the object changes     *        size.) This value can either be an absolute number if pivotXType     *        is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.     * @param pivotYType Specifies how pivotYValue should be interpreted. One of     *        Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or     *        Animation.RELATIVE_TO_PARENT.     * @param pivotYValue The Y coordinate of the point about which the object     *        is being scaled, specified as an absolute number where 0 is the     *        top edge. (This point remains fixed while the object changes     *        size.) This value can either be an absolute number if pivotYType     *        is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.     */    public ScaleAnimation(float fromX, float toX, float fromY, float toY,            int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) {        mResources = null;        mFromX = fromX;        mToX = toX;        mFromY = fromY;        mToY = toY;        mPivotXValue = pivotXValue;        mPivotXType = pivotXType;        mPivotYValue = pivotYValue;        mPivotYType = pivotYType;        initializePivotPoint();    }




参数如下
float fromX 动画起始时 X坐标上的伸缩尺寸
float toX 动画结束时 X坐标上的伸缩尺寸   
float fromY 动画起始时Y坐标上的伸缩尺寸   
float toY 动画结束时Y坐标上的伸缩尺寸   
int pivotXType 动画在X轴相对于物件位置类型   
float pivotXValue 动画相对于物件的X坐标的开始位置   
int pivotYType 动画在Y轴相对于物件位置类型   
float pivotYValue 动画相对于物件的Y坐标的开始位置  


说明
fromX,fromY
代表着你的这个View动画执行开始时的X轴方向和Y轴方向的缩放
尺寸,当为1.0f时就代表这和原来大小相同,当为2.0就是在X轴或Y轴方向上2倍尺寸大小。


toX,toY
和上边一样,代表着你的这个View动画执行结束时的X轴方向和Y轴方向的缩放
尺寸。


pivotXType,pivotYType
代表着这个View动画执行的过程中你指定的伸缩原点相对于你的物件位置如何设置的方式。它共有三种
模式,分别为Animation.ABSOLUTE,Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT
分别代表着绝对位置,相对于自己和相对于父布局的模式。当使用第一种时,比较简单,就是说把整个
动画的缩放中心点设置在一个相对于你的View的一个绝对位置处。当使用Animation.RELATIVE_TO_SELF和Animation.RELATIVE_TO_PARENT
就代表着你设定伸缩原点时使用相对位置,这个相对位置的参照物可以是你自己也可以是父布局。


pivotYValue,pivotXValue
这两个参数是和上面两个参数相关联的,也就是说当我们使用上面的两个参数设置好我们相对于物件位置类型时,
我们使用这两个参数来说明我们到底把这个伸缩原点放到哪里。这里我们就不讨论Animation.ABSOLUTE这种情况了
,比较简单。我们讨论Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT这两种模式下的参数的使用。
这两个参数是float类型,是相对的位置值,例如当你使用RELATIVE_TO_SELF模式并设置pivotXValue的值为0.5时,
就是说你的X轴方向的伸缩点设在你的这个View的X轴方向的中点处,同样如果你在把Y轴设为一样的方式。那么也就确定了
你的动画执行时的缩放原点为你的View的中心处,从这个中心点开始变大或缩小。
1 0