-1

我已经找了几个小时,但我在这段代码中找不到循环引用。我希望有人可以帮助我找到错误所在。

有问题的 XML 文件在这里;

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout android:id="@+id/politics_panel"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:orientation="vertical"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/leadership_panel"
        android:background="#66FF99" >

        <Spinner android:id="@+id/politics_spinner"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />

        <Button 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/ok"
            android:onClick="addCardToTray" /> 
    </LinearLayout>

    <LinearLayout android:id="@id/leadership_panel"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:orientation="vertical"
        android:layout_toLeftOf="@+id/tactics_panel"
        android:layout_toRightOf="@id/politics_panel"
        android:background="#3333CC">

        <Spinner android:id="@+id/leadership_spinner"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />

        <Button 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/ok"
            android:onClick="addCardToTray" />  
    </LinearLayout>

    <LinearLayout android:id="@id/tactics_panel"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:orientation="vertical"
        android:layout_toLeftOf="@+id/piloting_panel"
        android:layout_toRightOf="@id/leadership_panel"
        android:background="#CC3399" >

        <Spinner android:id="@+id/tactics_spinner"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />

        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/ok"
            android:onClick="addCardToTray" />
    </LinearLayout>

    <LinearLayout android:id="@id/piloting_panel"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:orientation="vertical"
        android:layout_toLeftOf="@+id/engineering_panel"
        android:layout_toRightOf="@id/tactics_panel"
        android:background="#FFFF00" >

        <Spinner android:id="@+id/piloting_spinner"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />

        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/ok"
            android:onClick="addCardToTray" />
    </LinearLayout>

    <LinearLayout android:id="@id/engineering_panel"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:orientation="vertical"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/piloting_panel"
        android:background="#990033" >

        <Spinner android:id="@+id/engineering_spinner"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />

        <Button
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/ok"
            android:onClick="addCardToTray" />
    </LinearLayout>
</RelativeLayout>

我运行代码时给出的 LogCat 打印输出是这样的;

04-09 21:49:32.834: E/AndroidRuntime(17888): FATAL EXCEPTION: main
04-09 21:49:32.834: E/AndroidRuntime(17888): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1321)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:317)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:337)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.View.measure(View.java:15530)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.View.measure(View.java:15530)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5109)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.View.measure(View.java:15530)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.View.measure(View.java:15530)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5109)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.View.measure(View.java:15530)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1986)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1227)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1400)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1120)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4604)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.Choreographer.doFrame(Choreographer.java:525)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.os.Handler.handleCallback(Handler.java:615)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.os.Looper.loop(Looper.java:137)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at android.app.ActivityThread.main(ActivityThread.java:4921)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
04-09 21:49:32.834: E/AndroidRuntime(17888):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

1

leadership_panelpolitics_panel,反之亦然。

于 2013-04-09T20:53:50.827 回答
0

leadership_panel为或选择一个位置politics_panel,而不是将每个位置相对于彼此放置而没有实际锚定。

于 2013-04-09T20:57:18.353 回答