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

标签 android animation

要将从左到右的比例应用于按钮,我使用了以下代码。我的按钮在布局的右侧。我希望按钮应该从它的右侧 X 位置开始并缩放到左侧 X 位置如何实现这一点?

view.startAnimation(new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f));

最佳答案

需要设置起点在右中,还需要这样设置动画的时长:

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);

在您的情况下,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, 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.

关于android - 如何从右到左缩放按钮,android动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7938798/

相关文章:

java - 为什么我不能从 android(Java) 中的另一个类更新类的变量?

Android:WebView shouldInterceptRequest 不在 WebView 中添加 RequestProperties

jquery - 如何在悬停时动画图像交换

javascript - for 循环动画的导航控件

java - 处理冲突 - 数组查找成本高昂

Android 虚拟设备不工作

windows-phone-7 - 如何使用Expression Blend在页面加载时自动播放 Storyboard 动画

android ScrollView 动画

android - 如何在其位置动态旋转图像?

android - HLS Stream Android 4.4.2 三星 Galaxy S5 上没有视频