无法解析xml中的ID

时间:2012-06-15 12:28:26

标签: android relativelayout android-xml

我正在尝试启动并运行RelativeLayout,因此我可以将其用于自定义列表, 但是当我试图将物品与其他物品相比较时,它会搞砸并说:

  

无法解析资源@id / itemName无法解析资源@ id / textPriceFrom

这很奇怪,因为textPriceFrom正确地放置了自己,但价格没有。

这是代码:

    <RelativeLayout
        android:id="@+id/mainlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

    <TextView
        android:id="@+id/itemName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dip"
        android:text="A good day"
        android:textSize="23dip"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textPriceFrom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/itemName"
        android:layout_margin="3dip"
        android:text="@string/frapris"
        android:textSize="15dip"
        android:textStyle="normal" />

    <TextView
        android:id="@+id/textPrice"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dip"
        android:layout_toLeftOf="@id/textPriceFrom"
        android:text="145,95"
        android:textSize="10dip"
        android:textStyle="normal" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_margin="3dip"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

我的android:layout_width="fill_parent"没有留下左/右关的空间,这显然是犯了这个错误。

答案 1 :(得分:0)

尝试使用@+id/textPriceFrom代替@id/textPriceFrom

我真的很抱歉我没有解释原因。但这就是它对我有用的方式。