缩放动画

6

我正在使用RotateAnimation来旋转图像。 但是我也希望在动画中对图像进行缩放。 也就是说,当我的图像旋转时,图像也在缩放...

如何在旋转动画中实现缩放?

3个回答

12

在 anim xml 中,您可以像这样使用缩放:

<scale
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromXScale=".1"
    android:fromYScale=".1"
    android:toXScale="1.0"
    android:toYScale="1.0"
    android:duration="2000" />

1
AnimationSet animSet = new AnimationSet(false); RotateAnimation rotate = new RotateAnimation(0,360,img.getWidth()/2,img.getHeight()/2); ScaleAnimation zoom = new ScaleAnimation(0, 50, 0, 50); animSet.addAnimation(rotate); animSet.addAnimation(zoom); animSet.setRepeatCount(0); animSet.setDuration(500); animSet.setFillAfter(true); animSet.setInterpolator(new AccelerateDecelerateInterpolator()); img.clearAnimation(); - Niranj Patel

12

在缩放动画中,这种动画被称为比例动画。

 ScaleAnimation scal=new ScaleAnimation(0, 1f, 0, 1f, Animation.RELATIVE_TO_SELF, (float)0.5,Animation.RELATIVE_TO_SELF, (float)0.5);
    scal.setDuration(500);
    scal.setFillAfter(true);
    ((ImageView)findViewById(R.id.logo)).setAnimation(scal);

非常好!谢谢! :) - Darshan

8
我有一个想法,希望能帮到你。
AnimationSet animSet = new AnimationSet(false);
RotateAnimation rotate = new RotateAnimation(0, 180);
ScaleAnimation zoom = new ScaleAnimation(0, 0, 1, 1);

animSet.addAnimation(rotate);
animSet.addAnimation(zoom);

animSet.start();

您应根据您的应用程序需要更改参数。


2
你应该玩弄属性(为动画设置正确的参数并不容易)。并将animSet动画添加到你的ImageView(或其他你使用的View)中。 - Pasha
1
ScaleAnimation的构造函数实际上是ScaleAnimation(float fromX, float toX, float fromY, float toY),因此为了使其起作用,它需要是ScaleAnimation(0,1,0,1)。 - Redshirt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接