Android的setVisibility(View.GONE)无效的问题及原因分析
2015-08-12 15:07
731 查看
出现这种情况很可能是因为设置了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的代码如下:
参考:http://bbs.csdn.net/topics/390311261
http://blog.csdn.net/xxxzhi/article/details/8846248 http://stackoverflow.com/questions/8690029/why-doesnt-setvisibility-work-after-a-view-is-animated http://www.cnblogs.com/liulipeng/p/3962101.html
实验证明只要在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://bbs.csdn.net/topics/390311261
http://blog.csdn.net/xxxzhi/article/details/8846248 http://stackoverflow.com/questions/8690029/why-doesnt-setvisibility-work-after-a-view-is-animated http://www.cnblogs.com/liulipeng/p/3962101.html
相关文章推荐
- Android不常见系统控件一览
- Android项目Tab类型主界面大总结 Fragment+TabPageIndicator+ViewPager
- Android端AES加密Bug解决方案
- android-----提交数据到服务器的4中方式
- Android 5.0 SDK 下载地址
- Bitmap基本概念及在Android4.4系统上使用BitmapFactory的注意事项
- 关于Android的问号?和@符号的用法
- Android的材料设计兼容库(Design Support Library)
- Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
- 设置android SurfaceView背景透明
- Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
- Android之TabHost布局
- Android View系统学习——从setContentView说开来
- 利用android工具创建Android项目
- Android Logcat调试中的V、D、I、W、E的分别代表什么?
- android QQ第三方登录(一)
- Android嵌套滑动组件相关的文章资料
- Android开发之ExpandableListView扩展(BaseExpandableListAdapter的使用)(完整版)
- android事件分发总结
- Android中ExpandableListView控件基本使用