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

时间:2014-04-15 13:35:10

标签: java android xml

嗨我无法弄清楚为什么我的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" />

任何人都可以帮忙解决这个问题吗?

由于

2 个答案:

答案 0 :(得分:3)

您正在将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>

答案 1 :(得分:3)

您正在使用

android:layout_above="@+id/top_content" 
按钮中的

android:layout_below="@+id/start_test" 
WebView中的

。只使用一个。

相关问题