【问题标题】:Circular dependencies, need some help with exact code循环依赖,需要一些确切代码的帮助
【发布时间】:2014-05-01 20:04:20
【问题描述】:

我对 Android 比较陌生,并且遇到了以下问题。我有一个 xml 布局代码,它似乎在 1.5 上工作,但在 1.6 上失败,并且在 RelativeLayout 中不允许使用循环依赖项。 我已经在谷歌上搜索了一些关于该错误的信息,并且我掌握了基础知识。关于这个主题的信息仍然太少。 我仍然无法弄清楚,我的代码中究竟在哪里发生了循环依赖。 请你们中的一些人指出发生这种情况的地方,并解释为什么会这样?

<LinearLayout  
    android:orientation="horizontal"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal">
    <ImageView
        android:paddingTop="3dip"
        android:id="@+id/typeicon"
        android:scaleType="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>  
</LinearLayout>

<RelativeLayout 
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="6.5"
    android:layout_height="fill_parent"
    android:paddingRight="20dip">
    <RelativeLayout
        android:layout_alignParentTop="true"
        android:id="@+id/toprellistlayout"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/trannumbertext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_alignParentLeft="true"/>
        <TextView
            android:id="@+id/summtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="16sp"
            android:layout_alignParentRight="true"
            android:textStyle="bold"/>
    </RelativeLayout>
    <TextView
        android:layout_below="@id/toprellistlayout"
        android:id="@+id/maintranstext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:textSize="13sp"
        android:textStyle="bold"
    />
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:paddingTop="4dip"
        android:layout_below="@id/maintranstext"
        android:id="@+id/toprellistlayout"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/datetext"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight=".3"
            android:textSize="11sp"
            android:text="01.01.0000 00:00:00"
            android:textStyle="bold"
            android:gravity="center"
            android:layout_alignParentLeft="true"/>
        <TextView
            android:id="@+id/statusview"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight=".7"
            android:gravity="center"
            android:text="@string/finlist_rejected"
            android:drawableLeft="@drawable/cross"
            android:drawablePadding="5dip"
            android:background="@android:id/empty"
            android:layout_alignParentRight="true"
            android:textStyle="bold"
            android:textSize="11sp"/>
    </RelativeLayout>
</RelativeLayout>

【问题讨论】:

  • 我建议为 1.6 版以后开发。出于商业原因,请看这里(developer.android.com/resources/dashboard/…)。从技术的角度来看,从 1.5 到 1.6 有很多变化,并且 API 从 1.6 开始是一致的。
  • 我面前没有 IDE 来渲染它,但乍一看,那些内部相对布局可能是简单的线性布局,只是在 textviews 上使用重力。
  • 是的,我正在为 1.6 开发并使用其中的库。但我仍然作为模拟器 1.5 之一进行调试。我将重写代码以使用线性布局,但这仍然很有趣——哪里有这种循环依赖。对于一般信息。也许它也可以帮助其他人。是的,上面提供的所有代码都在线性布局本身中,如果它很重要的话。

标签: android android-layout


【解决方案1】:

通过部分删除这些行一个小时后,我终于找到了“循环依赖项”的位置。

看来,当 SDK 解析 RelativeLayout xml 并定位项目时 - 例如,它不能采用位于视图 B 下方的视图 C,它位于视图 A 的下方。如果你仔细看 - 你'将在我的代码中找到该部分。
解决方案 - 是创建一个额外的RelativeLayout,用于放置视图 C 和 B。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    相关资源
    最近更新 更多