show multiple images animation

南笙酒味 提交于 2019-12-03 20:43:27

You could add the animator for all the images like this:

private final int REPEAT_COUNT = 1;
private final int REPEAT_MODE = 7;

private void startAnimations() {
    // Using the ImageView not the layout.
    ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1);
    ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2);
    ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3);
    ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4);
    ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5);
    ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6);

    ImageView snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6};

    // If it is not the same movement, you will need to create different layouts
    Animation snowMov1 = AnimationUtils.loadAnimation(this, R.layout.snowimg1);
    Animation snowMov2 = AnimationUtils.loadAnimation(this, R.layout.snowimg2);
    Animation snowMov3 = AnimationUtils.loadAnimation(this, R.layout.snowimg3);
    Animation snowMov4 = AnimationUtils.loadAnimation(this, R.layout.snowimg4);
    Animation snowMov5 = AnimationUtils.loadAnimation(this, R.layout.snowimg5);
    Animation snowMov6 = AnimationUtils.loadAnimation(this, R.layout.snowimg6);

    Animation movArray[] = {snowMov1, snowMov2, snowMov3, snowMov4, snowMov5, snowMov6};

    // Start the movement animation.
    startMovement(snowArray, movArray);
}

private void startMovement(ImageView imgArray[], Animation movArray[]) {
    // Same length so there is no problem...
    int length = imgArray.length;
    for(int i = 0; i < length; i++) {
        movArray[i].reset();
        movArray[i].setFillAfter(true);
        movArray[i].setAnimationListener(this);
        movArray[i].setRepeatCount(REPEAT_COUNT);
        movArray[i].setRepeatMode(REPEAT_MODE);

        // Start the animation
        imgArray[i].startAnimation(movArray[i]);
    }
}

You will need to make random movements in the animation file, this was not tested so Im not sure if it works... I hope it helps at least I tried.

EDIT:

Don't be impatient, help will come soon if my approach does not work!, you just need to wait man...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!