setVisibility(View.VISIBLE);setVisibility(View.GONE);setVisibility(View.INVISIBLE);都不起作用了,后来发现是设置动画原因。设置之前调用一下clearAnimation()就好了。
跟了一下源码发现setVisibility()方法会调用这个函数:
/**
* Do not invalidate views which are not visible and which are not running an animation. They
* will not get drawn and they should not set dirty flags as if they will be drawn
*/
private boolean skipInvalidate() {
return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null &&
(!(mParent instanceof ViewGroup) ||
!((ViewGroup) mParent).isViewTransitioning(this));
}
这个问题纠结的半天,网上搜了好久,没找到靠谱的答案。碰到bug查查源码是个好习惯。
本文探讨了当setVisibility()方法不起作用的原因及解决方案。通过清除视图动画并检查源码,揭示了这一问题背后的机制。
338

被折叠的 条评论
为什么被折叠?



