判断view是否可见

     判断一个view是否可见,我们平常用以下代码比较多

if(webView.getVisibility() == View.VISIBLE){
            //可见
        }else{
            //不可见
        }

但是有时候布局会嵌套,如:

    <LinearLayout
        android:id="@+id/llShow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#660000ff"
        android:orientation="vertical"
        android:padding="9dp">

        <TextView
            android:id="@+id/txtShow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#6600ff00"
            android:padding="9dp"
            android:text="txtShow" />
    </LinearLayout>

像上面的代码逻辑,如果整个外层就不显示,可以直接用外层llShow.getVisibility() == View.VISIBLE,判断是否显示,也可以用子view来判断,如:textShow.isShown(),效果是一样的。两种方法,具体可以根据实际场景灵活运用。

发布了33 篇原创文章 · 获赞 55 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wangsen927/article/details/104899274
今日推荐