为什么我的动画不重复?

时间:2014-12-16 16:06:35

标签: android animation

我已将repeatCount设置为 INFINITE ( - 1)并将repeatMode设置为 RESTART (1)

http://developer.android.com/reference/android/view/animation/Animation.html#INFINITE

即使我的动画有效,它也不会正确重复。我的代码中缺少什么?

public class SyncActivity extends Activity {

    Animation slideanim;
    ImageView senoide;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_sync);

        senoide = (ImageView) findViewById(R.id.imageView3);

        slideanim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
        //slideanim.setFillAfter(true);
        slideanim.setRepeatCount(Animation.INFINITE);
        slideanim.setRepeatMode(Animation.RESTART);

        senoide.setAnimation(slideanim);
        senoide.startAnimation(slideanim);
    }
}

move.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate android:fromXDelta="0%" android:toXDelta="-18.5%"
             android:fromYDelta="0%" android:toYDelta="0%"
             android:duration="1000"/>
</set>

1 个答案:

答案 0 :(得分:11)

将XML更改为具有重复模式并依赖它:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate android:fromXDelta="0%" android:toXDelta="-18.5%"
             android:fromYDelta="0%" android:toYDelta="0%"
             android:repeatCount="infinite"
             android:repeatMode="restart"
             android:duration="1000"/>
</set>