嗨,我尝试创建自定义布局,但我正在努力使其正常工作,但出现错误“相对布局中不存在循环依赖”

这就是我试图达到的布局术语,然后用数据填充每个文本字段的方法。

date                number
name   score - score  name
scorers              scorers

这是我的尝试
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:paddingTop="30dp"
    android:paddingBottom="30dp" >



    <TextView
        android:id="@+id/TextView04"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_below="@+id/HomeScore"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:text="-"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/AwayTeam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView04"
        android:layout_alignBottom="@+id/TextView04"
        android:layout_alignParentRight="true"
        android:layout_marginRight="22dp"
        android:gravity="left"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/HomeTeam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView04"
        android:layout_alignBottom="@+id/TextView04"
        android:layout_toRightOf="@+id/HomeScore"
        android:gravity="right"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/Attendance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/AwayTeam"
        android:layout_alignTop="@+id/HomeScore"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/Division"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView1"
        android:layout_toRightOf="@+id/HomeScore"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/AwayScore"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView04"
        android:layout_alignBottom="@+id/TextView04"
        android:layout_toRightOf="@+id/TextView04"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/HomeScore"
        android:layout_width="20dp"
        android:layout_height="wrap_content"

        android:layout_alignBottom="@+id/TextView04"
        android:layout_marginRight="15dp"
        android:layout_toLeftOf="@+id/TextView04"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue"
        android:textStyle="bold" />

</RelativeLayout>

继承人的错误
06-06 14:42:44.348: E/AndroidRuntime(1167): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1272)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:281)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:303)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.view.View.measure(View.java:8526)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.ListView.measureScrapChild(ListView.java:1153)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1266)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.ListView.onMeasure(ListView.java:1127)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.view.View.measure(View.java:8526)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3224)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:456)
06-06 14:42:44.348: E/AndroidRuntime(1167):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)

最佳答案

好吧,您在这里遇到一些问题:

  • TextView04声明android:layout_below="@+id/HomeScore"android:layout_centerVertical="true",它们与
  • 冲突
  • AwayTeam声明android:layout_alignBaseline="@+id/TextView04"android:layout_alignBottom="@+id/TextView04",它们与
  • 冲突
  • HomeTeam声明android:layout_alignBaseline="@+id/TextView04"android:layout_alignBottom="@+id/TextView04",它们与
  • 冲突
  • AwayScore声明android:layout_alignBaseline="@+id/TextView04"android:layout_alignBottom="@+id/TextView04",它们与
  • 冲突

    正如Samir所指出的,您的循环依赖关系中至少有一个在TextView04HomeScore之间。 TextView04表示它应位于HomeScore之下,HomeScore表示其底部与TextView04的底部对齐。但是,我上面提到的其他一些问题也可能会产生循环依赖关系。确保两个小部件不要试图在同一轴上相互约束(如TextView04HomeScore所示)。

    10-06 04:24