【问题标题】:Zoom in Animation放大动画
【发布时间】:2011-07-07 05:38:43
【问题描述】:

我正在使用RotateAnimation 作为图像。 但我也想用动画放大图像。 意味着当我的图像旋转时,图像也在缩放......

如何使用旋转动画进行缩放?

【问题讨论】:

    标签: android animation zooming


    【解决方案1】:

    在 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" />
    

    【讨论】:

    • AnimationSet animSet = new AnimationSet(false); RotateAnimation rotate = new RotateAnimation(0,360,img.getWidth()/2,img.getHeight()/2); ScaleAnimation 缩放 = new ScaleAnimation(0, 50, 0, 50); animSet.addAnimation(旋转); animSet.addAnimation(缩放); animSet.setRepeatCount(0); animSet.setDuration(500); animSet.setFillAfter(true); animSet.setInterpolator(new AccelerateDecelerateInterpolator()); img.clearAnimation();
    【解决方案2】:

    在 Zooming 动画中称为 Scale Animation。

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

    【讨论】:

    • 效果很好!谢谢! :)
    【解决方案3】:

    我有一个想法,希望对您有所帮助。

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

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

    【讨论】:

    • 您应该使用属性(为动画设置正确的参数并不容易)。并将animSet 动画添加到您的ImageView(或您使用的其他View)。
    • ScaleAnimation 构造函数实际上是 ScaleAnimation(float fromX, float toX, float fromY, float toY) 所以为了做任何事情都需要 ScaleAnimation(0,1,0,1);
    猜你喜欢
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    相关资源
    最近更新 更多