码迷,mamicode.com
首页 > 移动开发 > 详细

Android的setVisibility(View.GONE)无效的问题及原因分析(转)

时间:2016-12-09 16:30:15      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:app   protect   mat   apply   tar   lan   anim   初步   间接   

出现这种情况很可能是因为设置了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

Android的setVisibility(View.GONE)无效的问题及原因分析(转)

标签:app   protect   mat   apply   tar   lan   anim   初步   间接   

原文地址:http://www.cnblogs.com/zl1991/p/6149773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!