Android为什么我得到循环依赖异常



嗨,我不明白为什么我的xml布局会产生循环依赖关系?我知道它是什么,但不知道是什么引起的。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
    android:id="@+id/more_info"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent_black" >
    <Button
        android:id="@+id/start_test"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/top_content"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:onClick="onClickHandler"
        android:text="@string/start_test" />
    <WebView
        android:id="@+id/top_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/start_test" />
</RelativeLayout>
<WebView
    android:id="@+id/bottom_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/more_info"
    android:layout_alignParentBottom="true" />

有人能帮我解决这个问题吗?

感谢

您正在将android:layout_above="@+id/top_content"写入Button,将android:layout_below="@+id/start_test"写入WebView。这是在为RelativeLayout创建循环依赖项。


使用android:layout_above="@+id/top_content"android:layout_below="@+id/start_test"


所以要么使用

<RelativeLayout
    android:id="@+id/more_info"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent_black" >
    <Button
        ....
        android:layout_above="@+id/top_content"
        .... />
    <WebView
        android:id="@+id/top_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/more_info"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent_black" >
    <Button
        android:id="@+id/start_test"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:onClick="onClickHandler"
        android:text="@string/start_test" />
    <WebView
        android:id="@+id/top_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/start_test" />
</RelativeLayout>

您正在使用

android:layout_above="@+id/top_content" 

在按钮和中

android:layout_below="@+id/start_test" 

在WebView中。只使用一个。

最新更新