如何从右到左缩放一个按钮,android动画

前端之家收集整理的这篇文章主要介绍了如何从右到左缩放一个按钮,android动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
要将左到右比例应用于按钮,我使用了以下代码.我的按钮位于布局右侧.我想按钮应该从它的右X位置开始,并缩放到左X位置如何实现这个?
view.startAnimation(new ScaleAnimation(0.0f,1.0f,1.0f));

解决方法

您需要将起点设置为中间右侧,您还需要设置动画的持续时间,如下所示:
ScaleAnimation anim = new ScaleAnimation(0.0f,Animation.RELATIVE_TO_SELF,0.5f);
anim.setDuration(700);
view.startAnimation(anim);

在你的情况下,Y起始位置并不重要.

如果你没有读到这个构造函数

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,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,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.

原文链接:https://www.f2er.com/android/317564.html

猜你在找的Android相关文章