【问题标题】:RelativeLayout - Couldnt resolve resourceRelativeLayout - 无法解析资源
【发布时间】:2013-06-13 19:06:10
【问题描述】:

我有一个在运行时运行良好的相对布局,但在 Eclipse 图形布局设计器中我收到异常

无法解析资源@id/imgSessionOutcome_Product1_Icon

图像视图的资源已定义并且在对其的引用之前,所以我不太明白问题是什么?该异常被列出了两次,因此对它的两次引用都失败了。

我已经保存/清理了项目以确保资源重建,仍然是同样的错误。

Eclipse 版本:在 OSX 上运行的 Helios Service Release 2 具有最新更新等。

    <RelativeLayout
    android:id="@+id/lySessionOutcome_Product1"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="5dip"
    android:orientation="vertical" 
    android:visibility="gone">

    <ImageView
        android:id="@+id/imgSessionOutcome_Product1_Icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="10dip"
        android:src="@drawable/gr_bag_bc" />

    <TextView
        android:id="@+id/tvSessionOutcome_Product1_Description"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/imgSessionOutcome_Product1_Icon"
        android:ellipsize="marquee"
        android:singleLine="false"
        android:text="Description" />

    <TextView
        android:id="@+id/tvSessionOutcome_Product1_Type"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/tvSessionOutcome_Product1_Description"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@id/imgSessionOutcome_Product1_Icon"
        android:gravity="center_vertical"
        android:text="Product type"
        android:textAppearance="@style/largeBlack" />
</RelativeLayout>

【问题讨论】:

    标签: android android-layout android-relativelayout


    【解决方案1】:

    尝试使用

    android:layout_toRightOf="@+id/imgSessionOutcome_Product1_Icon"
    

    好吧,我很久以前就回答了这个问题,当时我不知道它为什么会起作用,但我仍然不确定,但根据我的观察,我认为使用 + 号会创建对视图的临时引用,以便我们可以在Android 布局编辑器,实际锚点视图仅在运行时获取。

    如果您不使用 + 符号,它在运行时可以正常工作,如问题本身所述。 如果我错了,请纠正我。

    【讨论】:

    • 哦,好的。我认为@+id 是当您向资源添加新 id 而不是引用现有资源时?我刚刚从 android 示例中删除了相对布局:developer.android.com/resources/articles/…
    • 现在工作了吗??? + 表示你想让它进入 R 文件,通常是你这样做的方式,但我不知道有时会出现这样的问题,不知道为什么
    • 是的 - 使用 @+id 引用有效。不明白为什么,我有其他相关的布局可以引用@id。我想我可能会在 res/values 中创建一个资源文件 ids.xml 然后总是用@id 引用而不是在布局。这是推荐的吗?
    • 我所知道的一切都告诉我这是错误的。如果有人对它的工作原理有答案,我很想听听!
    猜你喜欢
    • 2019-03-06
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多