ScrollView有很多示例,但我对RelativeLayout一无所知

在RelativeLayout中,某些视图将覆盖另一个视图。
我可以在xml中进行检查,但是如何使用Java代码进行检查?
使用isShown(),willNotDraw(),hasWindowFocus(),getLocalVisibleRect(),这些都不起作用。

案例1:容器布局确实在屏幕上

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--container layout is really on screen-->
    <fragment
        android:id="@+id/map_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <ImageView
            android:id="@+id/icon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>


案例2:容器布局实际上不在屏幕上

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <ImageView
            android:id="@+id/icon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            />
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            />
        </LinearLayout>
    </LinearLayout>

    <!--container layout is not really on screen-->
    <fragment
        android:id="@+id/map_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</RelativeLayout>

最佳答案

尝试使用这个

   if (myView.isShown()) {
        // Its visible
    } else {
        // Either gone or invisible
    }

10-07 19:16
查看更多