Android Relative Layout circular dependencies error

后端 未结 3 913
时光取名叫无心
时光取名叫无心 2020-12-06 11:26

Hi im trying to create a custom layout but i\'m struggling to get it to work properly i\'m getting an error \"circluar dependencies cannot exist in Relative layout\"

相关标签:
3条回答
  • 2020-12-06 11:44

    Remove android:layout_below="@+id/HomeScore" from first TextView in your layout it creates circular dependencies.

    Why ?

    Because you set android:layout_alignBottom="@+id/TextView04" in Textview whose id is android:id="@+id/HomeScore".and first Textview(TextView04) have also android:layout_below="@+id/HomeScore".

     <TextView
            android:id="@+id/TextView04"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true" 
            android:layout_centerHorizontal="true" 
            android:text="-"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/blue"
            android:textStyle="bold" />
    
    0 讨论(0)
  • 2020-12-06 11:45

    Well, you have a few problems here:

    1. TextView04 declares android:layout_below="@+id/HomeScore" and android:layout_centerVertical="true", which conflict

    2. AwayTeam declares android:layout_alignBaseline="@+id/TextView04" and android:layout_alignBottom="@+id/TextView04", which conflict

    3. HomeTeam declares android:layout_alignBaseline="@+id/TextView04" and android:layout_alignBottom="@+id/TextView04", which conflict

    4. AwayScore declares android:layout_alignBaseline="@+id/TextView04" and android:layout_alignBottom="@+id/TextView04", which conflict

    As Samir points out, at least one of your circular dependencies is between TextView04 and HomeScore. TextView04 says it is to be below HomeScore, and HomeScore says its bottom is aligned with the bottom of TextView04. However, some of the other ones I note above may also create circular dependencies. Ensure that two widgets do not try to constrain on each other on the same axis (as in TextView04 and HomeScore).

    0 讨论(0)
  • 2020-12-06 11:58

    You have a small mistake that might be the reason:

    When you reference to another id, don't use @+id/... just @id/.... So everywhere except the android:id attribute the + must be removed.

    After you have done that you might get some warnings that point to the possible error!

    0 讨论(0)
提交回复
热议问题