Android的setVisibility(View.GONE)不起作用在使用Animation之后.

出现这种情况很可能是因为设置了animation,并且调用了setFillAfter(true),这就会导致setVisibility无效,只需要调用一下clearAnimation()方法或者去掉setFillAfter(true)语句即可。

实验证明只要在setVisibility之前设置View的mCurrentAnimation为null就可以,因此调用setAnimation(null)也是可以的。从源码来看setFillAfter为false时也会间接导致调用clearAnimation,而clearAnimation在这里使setVisibility有效的原因也是置mCurrentAnimation为null了。

setFillAfter为false时间接导致clearAnimation:

这里写图片描述

而mCurrentAnimation使GONE无效的初步分析很可能是下面的代码造成:

这里写图片描述

在dispatchDraw子View的时候,尽管不为VISIBLE,由于是||的关系,也会导致drawChild被调用。而drawChild的代码如下:

 /**
     * Draw one child of this View Group. This method is responsible for getting
     * the canvas in the right state. This includes clipping, translating so
     * that the child's scrolled origin is at 0, 0, and applying any animation
     * transformations.
     *
     * @param canvas The canvas on which to draw the child
     * @param child Who to draw
     * @param drawingTime The time at which draw is occurring
     * @return True if an invalidate() was issued
     */
    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
        return child.draw(canvas, this, drawingTime);
    }

原文连接:http://www.cnblogs.com/albert1017/p/4724435.html

http://stackoverflow.com/questions/8690029/why-doesnt-setvisibility-work-after-a-view-is-animated

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值