在relativelayout中关联2小部件时出错

时间:2013-10-04 20:26:42

标签: android relativelayout

我试图关联小部件,我将代码编写为:

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:background="@drawable/ad1"
        android:orientation="horizontal" >

        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/ad1"
        android:orientation="horizontal"
        android:layout_toStartOf="@id/bt_menu" > // here there is error !!!!

        <EditText
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:hint="Menu "
        android:inputType="textVisiblePassword"/>
            </RelativeLayout>

        <ImageButton 
                 android:id="@+id/bt_menu" 
                 android:layout_width="50dp"
                 android:layout_height="50dp" 
                 android:layout_alignParentRight="true"
                 android:layout_alignParentTop="true"
                 android:background="@android:color/transparent"
                 android:scaleType="fitCenter" 
                 android:src="@drawable/menu5"
                 android:onClick="menu_onclick"/>
        </RelativeLayout>

我在这行中有错误:

机器人:layout_toStartOf = “@ ID / bt_menu”

错误是:找不到与给定名称匹配的资源(在'layout_toStartOf'中,值为'@ id / bt_menu')

任何人都可以帮助我!!!!

提前谢谢你...... Fadel。

2 个答案:

答案 0 :(得分:5)

将其更改为

 android:layout_toStartOf="@+id/bt_menu" >

添加“+”

如果它在您引用的layout之前,则Eclipse在保存之前似乎不知道它。在运行一次之后,您应该能够将其更改回原来的状态。但我不知道离开它会伤害任何事情。如果我使用诸如layout_below之类的属性但是将它放在View之前,我希望它相对于或类似的东西,我就这样做,但我只是留下它。

可能有一种更好的方法来处理这个问题,或者你正在使用的编辑器,但AFAIK,这是最简单的,我不知道它有任何不良影响。

答案 1 :(得分:0)

在我的选择中,不是两次使用“@ + id /”的最佳方法。您可以收到R.java文件的错误。您遇到的问题是,在设置之前使用了id。

解决方案:

  1. 首先按

    定义id

    android:layout_toStartOf="@+id/bt_menu"

  2. 使用ID

    android:id="@id/bt_menu"

相关问题