本文介绍了Android的相对布局循环依赖错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时喜试图创建一个自定义布局,但我挣扎得到它正常工作,我得到一个错误circluar依赖关系不能存在于相对布局

继承人什么我尝试获得了这幅布局的矿泉,然后填充每个文本字段的数据。

 日期数
名比分 - 比分名
射手榜的得分手
 

我的继承人尝试

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@色/白
    机器人:paddingTop =30dp
    机器人:paddingBottom会=30dp>



    <的TextView
        机器人:ID =@ + ID / TextView04
        机器人:layout_width =20dp
        机器人:layout_height =20dp
        机器人:layout_below =@ + ID / HomeScore
        机器人:layout_centerVertical =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:文本= -
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=@色/蓝色
        机器人:TEXTSTYLE =黑体/>

    <的TextView
        机器人:ID =@ + ID / AwayTeam
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / TextView04
        机器人:layout_alignBottom =@ + ID / TextView04
        机器人:layout_alignParentRight =真
        机器人:layout_marginRight =22dp
        机器人:重力=左
        机器人:文本=小文
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=@色/蓝色
        机器人:TEXTSTYLE =黑体/>

    <的TextView
        机器人:ID =@ + ID / HomeTeam
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / TextView04
        机器人:layout_alignBottom =@ + ID / TextView04
        机器人:layout_toRightOf =@ + ID / HomeScore
        机器人:重力=右
        机器人:文本=小文
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=@色/蓝色
        机器人:TEXTSTYLE =黑体/>

    <的TextView
        机器人:ID =@ + ID /考勤
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignRight =@ + ID / AwayTeam
        机器人:layout_alignTop =@ + ID / HomeScore
        机器人:文本=小文
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?

    <的TextView
        机器人:ID =@ + ID /科
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBottom =@ + ID / textView1
        机器人:layout_toRightOf =@ + ID / HomeScore
        机器人:文本=小文
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?

    <的TextView
        机器人:ID =@ + ID / AwayScore
        机器人:layout_width =20dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / TextView04
        机器人:layout_alignBottom =@ + ID / TextView04
        机器人:layout_toRightOf =@ + ID / TextView04
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=@色/蓝色
        机器人:TEXTSTYLE =黑体/>

    <的TextView
        机器人:ID =@ + ID / HomeScore
        机器人:layout_width =20dp
        机器人:layout_height =WRAP_CONTENT

        机器人:layout_alignBottom =@ + ID / TextView04
        机器人:layout_marginRight =15dp
        机器人:layout_toLeftOf =@ + ID / TextView04
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
        机器人:文字颜色=@色/蓝色
        机器人:TEXTSTYLE =黑体/>

< / RelativeLayout的>
 

继承人的错误

  06-06 14:42:44.348:E / AndroidRuntime(1167):java.lang.IllegalStateException:循环依赖不能RelativeLayout的存在
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.RelativeLayout $ DependencyGraph.getSortedViews(RelativeLayout.java:1272)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.RelativeLayout.sortChildren(RelativeLayout.java:281)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:303)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.view.View.measure(View.java:8526)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.ListView.measureScrapChild(ListView.java:1153)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.ListView.measureHeightOfChildren(ListView.java:1266)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.ListView.onMeasure(ListView.java:1127)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.view.View.measure(View.java:8526)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3224)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:456)
06-06 14:42:44.348:E / AndroidRuntime(1167):在android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
 

解决方案

好了,你有一些问题在这里:

  1. TextView04 声明安卓layout_below =@ + ID / HomeScore安卓:layout_centerVertical =真正的,其中冲突

  2. AwayTeam 声明安卓layout_alignBaseline =@ + ID / TextView04安卓:layout_alignBottom =@ + ID / TextView04,其中冲突

  3. HomeTeam 声明安卓layout_alignBaseline =@ + ID / TextView04安卓:layout_alignBottom =@ + ID / TextView04,其中冲突

  4. AwayScore 声明安卓layout_alignBaseline =@ + ID / TextView04安卓:layout_alignBottom =@ + ID / TextView04,其中冲突

由于萨米尔指出的那样,你的循环依赖中至少有一个是在 TextView04 HomeScore TextView04 说,这是要低于 HomeScore HomeScore 说其底部对准 TextView04 的底部。然而,一些其他的,我注意到上面还可以创建循环依赖。确保两个小部件不要尝试在同一轴线上相互约束(如 TextView04 HomeScore )。

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"

heres what im trying to acheive in termas of layout and then fill each text field with data.

date                number
name   score - score  name
scorers              scorers

heres my attempt

<?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>

heres the error

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)
解决方案

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).

这篇关于Android的相对布局循环依赖错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:25