简体   繁体   中英

Error when relate 2 widget in relativelayout

Im trying to relate widgets , I write the code as bellow:

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

I have an error in this line:

android:layout_toStartOf="@id/bt_menu"

The error is : no resource found that matches the given name (at 'layout_toStartOf' with value '@id/bt_menu')

Can anyone help me please !!!!

Thank you in advance .. Fadel.

Change it to

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

Add the "+"

If it is before the layout you are referencing then Eclipse doesn't seem to know about it until it has been saved. You should be able to change it back to how you have it after you have run it once. But I don't know that it will hurt anything to leave it. I do this if I use a property such as layout_below but put it before the View I want it to be relative to or something similar but I just leave it.

There may be a better way to handle this witin Eclipse, or whatever editor you are using, but AFAIK, this is the simplest and I don't know of any undesirable effects from it.

In my opition, is not the best way to use "@+id/" twice. You can receive errors of your R.java file. The problem you got is, that you use the id before you set it.

Solution:

  1. Define id first by

    android:layout_toStartOf="@+id/bt_menu"

  2. Use id

    android:id="@id/bt_menu"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM