To apply left to right scale toa button i have used the following code. My button is in the right of layout. I want the button should start from its right X position and scale to left X position how to achieve this?
view.startAnimation(new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f));
You need to set the starting point to the middle right, you also need to set the duration of the animation like this:
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 Y start location is not important.
if you don't get it read about this constructor:
public ScaleAnimation (float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
Since: API Level 1
Constructor to use when building a ScaleAnimation from code
Parameters:
fromX: Horizontal scaling factor to apply at the start of the animation
toX: Horizontal scaling factor to apply at the end of the animation
fromY: Vertical scaling factor to apply at the start of the animation
toY: Vertical scaling factor to apply at the end of the animation
pivotXType: Specifies how pivotXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
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.
pivotYType: Specifies how pivotYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With