Android在翻译动画上更改alpha

时间:2016-11-29 08:18:15

标签: android

我的翻译动画工作正常,我想更改小部件alpha在动画期间,例如我想将alpha 1.0设置为0.0当翻译动画时将我的小部件移动到底部,这是我的代码但改变alpha不能正常工作

public void SlideToAbove() {
    Animation slide = null;
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.2f);

    AnimationSet set = new AnimationSet(true);
    slide.setDuration(6000);

    set.addAnimation(slide);
    Animation anim = new AlphaAnimation(1.0f, 0.0f);
    anim.setDuration(100);
    set.addAnimation(anim);


    slide.setDuration(1500);
    slide.setFillAfter(true);
    slide.setFillEnabled(true);
    arrow.startAnimation(slide);
    slide.setRepeatCount(Animation.INFINITE);

    slide.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            arrow.clearAnimation();

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    arrow.getWidth(), arrow.getHeight());
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            arrow.setLayoutParams(lp);

        }

    });

}

1 个答案:

答案 0 :(得分:0)

原因是你根本不使用Alpha动画 您将其添加到集:

slide

并且不使用该集,但仅使用arrow.startAnimation(slide); 动画

.off()

代替。