Android ScaleAnimation不在屏幕中心

时间:2014-12-11 21:08:44

标签: android android-animation scaleanimation

在ImageView上实用地设置Scale动画时,我遇到了一些问题。 基本上我有和图像视图设置中心H / V,但当我应用动画时,它设置它:(...我读到关于枢轴x / y设置为50%,但它似乎不起作用,任何反馈将太棒了......下面的屏幕截图

    AnimationSet set = new AnimationSet(true);
    Animation animation = new ScaleAnimation(1, 1.2f, 1, 1.2f, Animation.ABSOLUTE, 50,    Animation.ABSOLUTE, 50);
    animation.setDuration(500);
    animation.setRepeatCount(-1);
    animation.setRepeatMode(Animation.RESTART);
    set.addAnimation(animation);

    animation = new ScaleAnimation(1.2f, 1.4f, 1.2f, 1.4f, Animation.ABSOLUTE, 50, Animation.ABSOLUTE, 50);
    animation.setDuration(500);
    animation.setRepeatCount(-1);
    animation.setRepeatMode(Animation.RESTART);
    set.addAnimation(animation);

    animation = new ScaleAnimation(1.4f, 1.0f, 1.4f, 1.0f, Animation.ABSOLUTE, 50, Animation.ABSOLUTE, 50);
    animation.setDuration(500);
    animation.setRepeatCount(-1);
    animation.setRepeatMode(Animation.RESTART);
    set.addAnimation(animation);

    image_view.startAnimation(set);

enter image description here

1 个答案:

答案 0 :(得分:3)

也许Animation.RELATIVE_TO_SELFAnimation.RELATIVE_TO_PARENT可以完成这项工作吗?例如:

new ScaleAnimation(1, 1.2f, 1, 1.2f,
            Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f));

0.5f视为50%,从左/上计算