2012-03-19 52 views
1

我有个亲戚布局,在运行时,但在Eclipse图形布局设计师,我收到异常正常工作的RelativeLayout - 不可能解决资源

无法解析资源@ ID/imgSessionOutcome_Product1_Icon

的资源imageview被定义并且在引用它之前,所以我不太明白这个问题是什么?该例外列出两次,因此对它的引用都失败。

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

Eclipse版本:赫利俄斯服务版本2上运行OSX最新更新等

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

回答

6

尝试使用

android:layout_toRightOf="@+id/imgSessionOutcome_Product1_Icon" 

嗯,我这个很久以前我不知道为什么它的工作原理回答然后我仍然不确定,但根据我的观察,我认为使用+符号会创建临时引用视图,以便我们可以在Android布局编辑器中查看它,实际锚点视图仅在运行时被选中。

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

+0

哦,好的。我以为@ + id是在向资源中添加新标识而不是引用现有资源时?我刚刚从android示例中删除了相关的布局:http://developer.android.com/resources/articles/layout-tricks-efficiency.html – MartinS 2012-03-19 10:11:02

+0

它现在正在工作吗? +意思是你想让它进入R文件它通常是你这样做的方式,但我不知道有时候出现这样的问题donno为什么 – 2012-03-19 10:13:31

+0

是的 - 引用@ + id的作品。 不明白为什么,但我有其他相关的布局,它引用@id。我想我可以使资源的资源文件ids.xml /值 <项目类型= “ID” NAME = “imgSessionOutcome_Product1_Icon”/> 然后总是@ id引用,而不是使用@ + ID在布局。这是建议吗? – MartinS 2012-03-19 10:17:59

相关问题