Reputation: 465
Here is my (relevant) XML code:
<RelativeLayout
<Button
android:id="@+id/menu_button"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_marginBottom="60dp"
android:layout_marginTop="8dp"
android:background="@mipmap/ic_launcher"
android:onClick="myOnClickMethod"
android:layout_below="@id/whiteBackground" <---- ERROR HERE
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"/>
<ImageView
android:id="@+id/whiteBackground" <---- HERE IS THE ID
android:layout_width="350dp"
android:layout_height="350dp"
android:contentDescription="@string/white_background"
android:tag="white"
android:visibility="visible"
android:background="@drawable/myrect"
android:elevation="15dp"
android:layout_below="@id/image_text_editor"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/text_size_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/size"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:visibility="visible"
android:onClick="SizeChange"
android:layout_below="@id/whiteBackground" <---- ALSO BEING USED HERE (NO ERROR)
android:layout_toLeftOf="@id/menu_button"/>
<Button
android:id="@+id/move_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu_button"
android:layout_below="@id/whiteBackground" <----ALSO BEING USED HERE (NO ERROR)
android:layout_margin="8dp"
android:onClick="MoveChange"
android:text="MOVE"/>
</RelativeLayout>
I'm getting an error on the noted line above. It's telling me
No resource found that matches the given name (at 'layout_below' with value '@id/whiteBackground').
I'm not sure why this is happening because as you can see the ID/element is sitting right below it where noted. And as you can see the other 2 buttons below that also use the same layout_below="@id/whiteBackground"
and there are no errors there. It's just the 1 line.
If someone could tell me what's going on, that would be greatly appreciated.
Thanks
Upvotes: 1
Views: 117
Reputation: 8237
Try this in your code .
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/menu_button"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/whiteBackground"
android:layout_centerInParent="true"
android:layout_marginBottom="60dp"
android:layout_marginTop="8dp"
android:background="@mipmap/ic_launcher"
android:onClick="myOnClickMethod" />
<ImageView
android:id="@+id/whiteBackground"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_below="@+id/image_text_editor"
android:layout_centerInParent="true"
android:background="@drawable/myrect"
android:contentDescription="@string/white_background"
android:elevation="15dp"
android:tag="white"
android:visibility="visible" />
<Button
android:id="@+id/text_size_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/whiteBackground"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_toLeftOf="@id/menu_button"
android:onClick="SizeChange"
android:text="@string/size"
android:visibility="visible" />
<Button
android:id="@+id/move_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/whiteBackground"
android:layout_margin="8dp"
android:layout_toRightOf="@id/menu_button"
android:onClick="MoveChange"
android:text="MOVE" />
</RelativeLayout>
Add height and width in the root of the xml code .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
make sure that the id is existed .
android:layout_below="@+id/image_text_editor"
Upvotes: 1
Reputation: 1791
You can change
layout_below="@id/whiteBackground"
to
layout_below="@+id/whiteBackground"
I hope it will hope you!
Upvotes: 2