0
在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" />
檢查您的UI元素的相對位置。如果你所說的是「讓元素X在元素Y下面」並且還有一個條件「讓元素Y在元素X下面」,那麼創建循環依賴關係。所以,梳理xml文件,並在紙上繪製出與每個元素相關並與屏幕邊緣相關的東西。另外,請避免使用id值,例如「@ + id/textView」。給出有意義的名稱,如「@ + id/login_textview」等,有助於簡化閱讀和命名衝突。 – 2014-11-02 00:19:47