我希望我的ImageView从屏幕中心滚动到右侧。我现在使用此代码,但它不会滚动图像。

final AnimationSet rollingIn = new AnimationSet(true);

Animation moving = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0,
    Animation.RELATIVE_TO_PARENT, 0);
moving.setDuration(5000);

rollingIn.addAnimation(moving);

最佳答案

尝试

final AnimationSet rollingIn = new AnimationSet(true);
    Animation moving = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 5, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    moving.setDuration(1000);
    final Animation rotating = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotating.setDuration(1000);

    rollingIn.addAnimation(rotating);
    rollingIn.addAnimation(moving);

09-10 08:46