Imageview可见性在动画之前受到影响

时间:2017-04-11 03:44:13

标签: android animation imageview visibility

我在项目中使用了一些动画:

我有自己的动画课程:

public class Anim1Foto implements Animator.AnimatorListener {
    private ImageView imagen1;
    private ImageView imagen2;

public Anim1Foto (ImageView pimagen1,ImageView pimagen2){
    this.imagen1 = pimagen1;
    this.imagen2 = pimagen2;
}
@Override
public void onAnimationStart(Animator animation) {

}

@Override
public void onAnimationEnd(Animator animation) {

    AnimatorSet as = new AnimatorSet();

    ObjectAnimator anim = ObjectAnimator.ofFloat(imagen1, "translationY", 0,200);
    anim.setDuration(2500);


     as.playSequentially(anim);
    as.start();

    imagen1.setVisibility(View.INVISIBLE);

}

@Override
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

    }
}

我想要做的是翻译我的Imageview然后使用“setVisibility(INVISIBLE)”使其消失,但我得到的是,在进行一些测试后,在初始化时,imageview根本没有出现引导我得出结论:在动画设置开始之前,可见性受到影响......我猜错了?如果是这样,那么这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

请尝试: -

public class Anim1Foto implements Animator.AnimatorListener {
    private ImageView imagen1;
    private ImageView imagen2;

public Anim1Foto (ImageView pimagen1,ImageView pimagen2){
    this.imagen1 = pimagen1;
    this.imagen2 = pimagen2;
}
@Override
public void onAnimationStart(Animator animation) {

}

@Override
public void onAnimationEnd(Animator animation) {

    AnimatorSet as = new AnimatorSet();

    ObjectAnimator anim = ObjectAnimator.ofFloat(imagen1, "translationY", 0,200);
    anim.setDuration(2500);


     as.playSequentially(anim);
    as.start();

    anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imagen1.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

}

@Override
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

    }
}