查看getVisibility()isShown()返回不正确的知名度不正确、知名度、getVisibility、isShown

2023-09-06 17:23:23 作者:是命i

我已经是被有条件地加入到父视图。 我检查,如果它已经加入到父母与否,不幸的是,它总是返回其可见。

I've a view that gets conditionally added to parent. I check if its already added to parent or not, unfortunately, it always return its visible.

if (findViewById(R.id.bottom_bar).getVisibility == View.Visible)

if (findViewById(R.id.bottom_bar).isShown()) 

都返回即使观点从未被添加ANS是不可见的。

both return true even when view was never added ans is not visible.

推荐答案

getVisibility()直接返回你想的时候添加到窗口视图有知名度。除非你调用它并没有改变 setVisibility()。它也并不表示该视图是在屏幕上实际可见。

getVisibility() simply returns the visibility you want the view to have when added to the window. It doesn't change unless you call setVisibility(). It also doesn't indicate whether the view is actually visible on screen.

isShown()是相似的。这里是DOC:

isShown() is similar. Here is the doc:

返回此观点的知名度和它的所有祖先

Returns the visibility of this view and all of its ancestors

返回   如果此观点及其所有祖先是可见

Returns True if this view and all of its ancestors are VISIBLE