Android 呈现期间引发异常:循环依赖项不能存在

Android 呈现期间引发异常:循环依赖项不能存在,android,xml,user-interface,Android,Xml,User Interface,在Android Studio中编辑activity_main.xml中的GUI时,突然出现上述错误。我对XML一点也不熟悉(我只是这个应用程序的设计者),如果有任何帮助,我会非常感激,让它重新运行,这样我就可以继续设计了 <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:i

在Android Studio中编辑activity_main.xml中的GUI时,突然出现上述错误。我对XML一点也不熟悉(我只是这个应用程序的设计者),如果有任何帮助,我会非常感激,让它重新运行,这样我就可以继续设计了

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView" />

<SeekBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/seekBar"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="162dp" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton"
    android:layout_toEndOf="@+id/seekBar"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/imagebutton1"
    android:layout_marginBottom="243dp"
    android:layout_above="@+id/seekBar"
    android:layout_toStartOf="@+id/textView2" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton2"
    android:background="@drawable/imagebutton2"
    android:layout_toEndOf="@+id/textView2"
    android:layout_gravity="center|left"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="68dp"
    android:layout_alignBottom="@+id/textView3" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Partly Cloudy"
    android:id="@+id/textView3"
    android:textColor="#D1DBBD"
    android:textSize="20dp"
    android:textAlignment="center"
    android:layout_alignEnd="@+id/textView2"
    android:layout_alignBottom="@+id/imageButton2" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="22 ºC"
    android:id="@+id/textView2"
    android:textSize="40dp"
    android:textColor="#D1DBBD"
    android:textAlignment="center"
    android:textIsSelectable="true"
    android:layout_alignBaseline="@+id/textView3"
    android:layout_alignBottom="@+id/textView3"
    android:layout_alignStart="@+id/textView3" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:background="@drawable/line"
    android:layout_marginBottom="60dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Bradford"
    android:id="@+id/textView4"
    android:layout_toStartOf="@+id/imageButton2"
    android:textAlignment="center"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignStart="@+id/textView2"
    android:textSize="20dp"
    android:textColor="#193441" />



循环依赖是指资源A依赖于资源B,但资源B也依赖于A。类似于
A->B->A
,形成一个“循环”

在您的例子中,资源是视图,我可以看到至少一个循环依赖关系:您的
textView2
依赖于
textView3
android:layout\u alignBaseline=“@+id/textView3”
),它本身依赖于
textView2
android:layout\u alignEnd=“@+id/textView2”
)。发生这种情况时,系统无法正确对齐它们


尝试以另一种方式安排布局以避免这种情况。使用
LinearLayout
RelativeLayout
对多个视图进行分组,如果这样做更方便的话。

检查UI元素的相对位置。如果您说的是“让元素X在元素Y之下”之类的话,以及“让元素Y在元素X之下”这样的条件,那么就会创建循环依赖项。因此,梳理xml文件并在纸上绘制出与每个元素和屏幕边缘相关的内容。另外,避免使用诸如“@+id/textView”之类的id值。给出有意义的名称,如“@+id/login\u textview”等,有助于阅读和命名冲突。