[Solved] Java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout

  1. <?xml version=“1.0” encoding=”utf-8″?>  
  2. <ScrollView xmlns:android=“http://schemas.android.com/apk/res/android”  
  3.     android:layout_width=“fill_parent”  
  4.     android:layout_height=“wrap_content” >  
  5.     <HorizontalScrollView  
  6.         android:layout_width=“fill_parent”  
  7.         android:layout_height=“wrap_content” >  
  8.         <RelativeLayout  
  9.             android:layout_width=“fill_parent”  
  10.             android:layout_height=“fill_parent”>  
  11.             <TextView  
  12.                 android:id=“@+id/textview1”  
  13.                 android:layout_width=“wrap_content”  
  14.                 android:layout_height=“wrap_content”  
  15.                 android:text=“Scrolling view”  
  16.                 android:textSize=“30dp” />  
  17.             <ImageView  
  18.                 android:id=“@+id/imageview1”  
  19.                 android:layout_width=“wrap_content”  
  20.                 android:layout_height=“wrap_content”  
  21.                 android:layout_toRightOf=“@id/textview1”  
  22.                 android:src=“@drawable/item1” />  
  23.             <TextView  
  24.                 android:id=“@+id/textview2”  
  25.                 android:layout_width=“wrap_content”  
  26.                 android:layout_height=“wrap_content”  
  27.                 android:layout_toRightOf=“@id/imageview1”  
  28.                 android:text=“Vertical and horizontal scrolling”  
  29.                 android:textSize=“30dp” />  
  30.             <ImageView  
  31.                 <span style=“color:#ff6666;”>android:id=”@+id/imageview2″  
  32. </span>                android:layout_width=“wrap_content”  
  33.                 android:layout_height=“wrap_content”  
  34.                 android:layout_below=“@id/textview1”  
  35.                 android:src=“@drawable/item2” />  
  36.             <TextView  
  37.                 android:id=“@+id/textview3”  
  38.                 android:layout_width=“wrap_content”  
  39.                 android:layout_height=“wrap_content”  
  40.                 android:layout_below=“@id/imageview2”  
  41.                 android:text=“Vertical and horizontal scrolling”  
  42.                 android:textSize=“30dp” />  
  43.             <ImageView  
  44.                <span style=“color:#ff6666;”> android:id=”@+id/imageview2″</span>  
  45.                 android:layout_width=“wrap_content”  
  46.                 android:layout_height=“wrap_content”  
  47.                 android:layout_below=“@id/textview3”  
  48.                 android:src=“@drawable/item3” />  
  49.         </RelativeLayout>  
  50.     </HorizontalScrollView>  
  51. </ScrollView>  

 

Such an exception broke out, java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout.

The reason is that duplicate view ID names are reproduced in the RelativeLayout layout, and imageview2, textview3, and imageview2 have circular dependencies.

Solution: Modify the id of the last ImageView to imageview3. Avoid the control cycle dependency in RelativeLayout.

The essence is: the position of 1 depends on the position relative to 2 and 2 depends on the position relative to 1, but the two relative positions are contradictory.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *