Why am I getting a CircularDependencyException?

十年热恋 提交于 2019-11-29 11:31:44

RelativeLayout "left" is trying to lay itself out based on the location of RelativeLayout "right". This cannot be done, because as the exception says, it's circular. How can you park a car based on the parking of another car if that car is still moving?

Based on your xml file, I recommend you use LinearLayouts. There really isn't anything that you are doing here that can't be solved with two LL's and the parent RelativeLayout.

Remove the line android:layout_toLeftOf="@+id/right". You are declaring left to be to the left of right, and then right to be to the right of left. Its a circular dependency because it does not know which element to lay out first.

You try to refer two layouts each other in your layout. A part of codes shows as below,

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:id="@+id/left"
        android:layout_toLeftOf="@+id/right" />
    <RelativeLayout
        android:id="@+id/right"
        android:layout_toRightOf="@+id/left" />
 </RelativeLayout>

It will occur circular dependency exception.

How to fix?

Set gravity type of one layout, Other layout refers this.

For this case, remove android:layout_toRightOf="@+id/left"

Because default layout gravity is left, then remove this line. It will be fine.

Have fun @.@

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!