前置き
Viewの表示状態を見て処理を振り分けたいケースがあると思います。
以前はこうしてました↓
java
if(view.getVisibility() == View.VISIBLE){
// 見えとるやんけ!
}
修正してみた
でもほら、isShown()ってそれっぽい関数があるじゃないですか。
で、そっち使うように修正するじゃないですか。
java
if(view.isShown()){
// 見えとるのに、ここ通らねぇw ワロリッシュw
}
動かねぇ
ふーむ。isShown()って関数名はそれっぽいんだけど。
ソースコードはこんな感じで動いてくれても良さそうなんだけどなぁ。
parentで先祖遡ってるうちに、どっかでfalse返してるのかな?
java
/**
* 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;
}
結局
onResume() のタイミングで isShown() するとfalse返すみたいなのよね。
ダメ、絶対。
どうしてもonResume()で判断したい場合は?
getVisivility()でがんばろう