How to scale the button from right to left, android animation

To apply the button from left to right, I used the following code. My button is on the right side of the layout. I want the start button from the right X position and scale to the left X position, how to do this?

view.startAnimation(new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f)); 
+6
source share
1 answer

You need to set the starting point in the middle of the right, you also need to set the animation duration as follows:

 ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,1.0f, Animation.RELATIVE_TO_SELF, 0.5f); anim.setDuration(700); view.startAnimation(anim); 

in your case, the location of the beginning of Y is not important.

if you don’t know about this constructor:

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

Because: API Level 1

Constructor used when building ScaleAnimation from code

Parameters:

fromX: The horizontal zoom factor to apply at the beginning of the animation

toX: The horizontal zoom factor to apply at the end of the animation

fromY: Vertical scale factor to apply at the beginning of the animation

toY: Vertical scale factor for use at the end of the animation

pivotXType: Indicates how to interpret the value of pivotXValue. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF or Animation.RELATIVE_TO_PARENT.

pivotXValue: The X coordinate of the point at which the object is scaled, specified as an absolute number, where 0 is the left edge. (This point remains fixed, and the object changes size.) This value can be an absolute number if pivotXType is ABSOLUTE, or a percentage (where 1.0 - 100%) otherwise.

pivotYType: Indicates how to interpret the value of pivotYValue. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF or Animation.RELATIVE_TO_PARENT.

pivotYValue: The Y coordinate of the point at which the object is scaled is defined as an absolute number, where 0 is the top edge. (This point remains fixed, and the object changes size.) This value can be either an absolute number if pivotYType is ABSOLUTE, or a percentage (where 1.0 - 100%) otherwise.

+16
source

Source: https://habr.com/ru/post/900338/


All Articles