先贴源码
/** * Returns the visibility of this view and all of its ancestors * * @return True if this view and all of its ancestors are {@link #VISIBLE} */ public boolean isShown() { View current = this; //noinspection ConstantConditions do { if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { return false; } ViewParent parent = current.mParent; if (parent == null) { return false; // We are not attached to the view root } if (!(parent instanceof View)) { return true; } current = (View) parent; } while (current != null); return false; }
根据上面得文档可以得知此方法是检查此视图及父视图是否可见,
if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { return false; }
如果此视图及父视图不可见则返回false,如果每一层父视图和此视图都可见则返回true
此方法不可在视图绘制时调用,应在视图绘制完成之后调用
关注CC 不定时更新你需要或你用不到的知识( $ _ $ )