peter97silva
peter97silva

Reputation: 15

Circular layout dependencies

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="roteiro.pap.pedro.roteiro.Filtros"
android:background="@drawable/fundo_ceu"
android:id="@+id/fundo">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Dormir"
    android:id="@+id/btnDormir"
    android:layout_centerVertical="true"
    android:onClick="btnDormironClick"
    android:layout_alignLeft="@+id/btnNatureza"
    android:layout_alignStart="@+id/btnNatureza"
    android:layout_alignRight="@+id/btnNatureza" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Info"
    android:id="@+id/btnInfo"
    android:onClick="btnInfoonClick"
    android:layout_above="@+id/btnDormir"
    android:layout_alignRight="@+id/btnNatureza"
    android:layout_alignLeft="@+id/btnNatureza"
    android:layout_alignStart="@+id/btnNatureza" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Comer"
    android:id="@+id/btnComer"
    android:onClick="btnComeronClick"
    android:layout_below="@+id/btnDormir"
    android:layout_alignRight="@+id/btnDormir"
    android:layout_alignEnd="@+id/btnDormir"
    android:layout_alignLeft="@+id/btnNatureza"
    android:layout_alignStart="@+id/btnNatureza" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Bares"
    android:id="@+id/btnBar"
    android:onClick="btnBaronClick"
    android:layout_below="@+id/btnComer"
    android:layout_alignRight="@+id/btnComer"
    android:layout_alignEnd="@+id/btnComer"
    android:layout_alignLeft="@+id/btnNatureza"
    android:layout_alignStart="@+id/btnNatureza" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:layout_toEndOf="@+id/imageView11"
    android:src="@drawable/monumentos"
    android:layout_toRightOf="@+id/imageView11" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView3"
    android:layout_alignBottom="@+id/btnInfo"
    android:layout_toRightOf="@+id/btnInfo"
    android:layout_toEndOf="@+id/btnInfo"
    android:src="@drawable/info" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView4"
    android:layout_above="@+id/btnComer"
    android:layout_toRightOf="@+id/btnDormir"
    android:layout_toEndOf="@+id/btnDormir"
    android:src="@drawable/dormir" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Compras"
    android:id="@+id/btnCompras"
    android:onClick="btnComprasonClick"
    android:layout_below="@+id/btnBar"
    android:layout_alignRight="@+id/btnBar"
    android:layout_alignEnd="@+id/btnBar"
    android:layout_alignLeft="@+id/btnNatureza"
    android:layout_alignStart="@+id/btnNatureza" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView5"
    android:layout_above="@+id/btnBar"
    android:layout_toRightOf="@+id/btnComer"
    android:layout_toEndOf="@id/btnComer"
    android:src="@drawable/comer" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView6"
    android:layout_above="@+id/btnCompras"
    android:layout_toRightOf="@+id/btnBar"
    android:layout_toEndOf="@id/btnBar"
    android:src="@drawable/bar" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView7"
    android:layout_alignBottom="@+id/btnCompras"
    android:layout_toRightOf="@+id/btnCompras"
    android:layout_toEndOf="@+id/btnBar"
    android:src="@drawable/compras" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Natureza"
    android:id="@+id/btnNatureza"
    android:onClick="btnPassearonClick"
    android:layout_above="@+id/imageView2"
    android:layout_marginBottom="10dp"
    android:layout_toLeftOf="@+id/imageView11"
    android:layout_toStartOf="@+id/imageView11" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView11"
    android:layout_toEndOf="@+id/btnNatureza"
    android:src="@drawable/passear"
    android:layout_alignBottom="@+id/btnNatureza"
    android:layout_toRightOf="@+id/btnNatureza" />

I've got the circular dependencies error on my layout, ive tried to find any circular dependency but couldnt find it, anyone who sees?

java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout

Upvotes: 0

Views: 100

Answers (3)

Kent Hawkings
Kent Hawkings

Reputation: 2793

The error lies in the following components

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Natureza"
    android:id="@+id/btnNatureza"
    android:onClick="btnPassearonClick"
    android:layout_above="@+id/imageView2"
    android:layout_marginBottom="10dp"
    android:layout_toLeftOf="@+id/imageView11"
    android:layout_toStartOf="@+id/imageView11" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView11"
    android:layout_toEndOf="@+id/btnNatureza"
    android:src="@drawable/passear"
    android:layout_alignBottom="@+id/btnNatureza"
    android:layout_toRightOf="@+id/btnNatureza" />

You specify that btnNatureza must be to the right of imageView11 but then you tell imageView11 that it must be to the left of btnNatureza. This is a circular dependancy since there is no starting point of reference for either view, they rely on each other to determine their position. In order to fix this you must remove either android:layout_toLeftOf="@+id/imageView11" from the Button or android:layout_toRightOf="@+id/btnNatureza" from the ImageView

Upvotes: 1

fstef
fstef

Reputation: 379

These two views reference each other

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Natureza"
android:id="@+id/btnNatureza"
android:onClick="btnPassearonClick"
android:layout_above="@+id/imageView2"
android:layout_marginBottom="10dp"
android:layout_toLeftOf="@+id/imageView11"
android:layout_toStartOf="@+id/imageView11" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView11"
android:layout_toEndOf="@+id/btnNatureza"
android:src="@drawable/passear"
android:layout_alignBottom="@+id/btnNatureza"
android:layout_toRightOf="@+id/btnNatureza" />

Upvotes: 0

Michael Laffargue
Michael Laffargue

Reputation: 10304

btnNatureza refers to imageView2 which refers to imageView11 which refers to btnNatureza

Also in general you can't say A is at the bottom of B and B is above A. Just keep one.

<Button
    android:id="@+id/btnNatureza"
    android:layout_above="@+id/imageView2"
    android:layout_toLeftOf="@+id/imageView11"
    android:layout_toStartOf="@+id/imageView11" />

<ImageView
    android:id="@+id/imageView11"
    android:layout_toEndOf="@+id/btnNatureza"
    android:layout_alignBottom="@+id/btnNatureza"
    android:layout_toRightOf="@+id/btnNatureza" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_toEndOf="@+id/imageView11"
    android:layout_toRightOf="@+id/imageView11" />

Upvotes: 0

Related Questions