动画效果view消失后,再次设置visible无效的问题

前情提要:项目需要动效让一个view移动到屏幕边缘附近就消失,并在animationend的时候设置了当前View布局Gone。但是需要在进入下级页面如果打开展示开关时继续展示。

问题描述:从下级页面返回回来在onResume中获取状态并设置view展示,但是view都没有展示出来

问题原因:

动画导致对象view的位置变换,由于当前页面并没有销毁,所以动画的作用仍旧存在,导致即使设置view VISIBLE,仍旧无法展示出来。

 

解决方案:

方案一 animator.reverse():

        对于简单的位移或者透明度等变化,可以直接使用reverse方法,但是由于项目动效较为复杂,需要对前一个动画进行监听并在其结束后进行后续动画操作,所以改方法不适用,这样会导致reverse之后,动画不断的循环往复的之类的问题,达不到预期效果。

原因在于reverse方法其实就是把该动画对象从end到start反过来再播放一遍动效

/**
 * Plays the ValueAnimator in reverse. If the animation is already running,
 * it will stop itself and play backwards from the point reached when reverse was called.
 * If the animation is not currently running, then it will start from the end and
 * play backwards. This behavior is only set for the current animation; future playing
 * of the animation will use the default behavior of playing forward.
 */
@Override
public void reverse() {
    if (isPulsingInternal()) {
        long currentTime = AnimationUtils.currentAnimationTimeMillis();
        long currentPlayTime = currentTime - mStartTime;
        long timeLeft = getScaledDuration() - currentPlayTime;
        mStartTime = currentTime - timeLeft;
        mStartTimeCommitted = true; // do not allow start time to be compensated for jank
        mReversing = !mReversing;
    } else if (mStarted) {
        mReversing = !mReversing;
        end();
    } else {
        start(true);
    }
}

方案二:

类似TranslateAnimation,AnimationSet属于Animation子类的这样的动画,可以直接使用setFillBefore或者setFillAfter这样的方法设置动画结束后,需要在那里展示。但是由于项目需要的不是在动画后立刻生效,所以并不适用。

方案三:

直接对目标view对象进行简单的位置,scale,alpha等进行设置。问题解决。 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值