关于android:找不到与给定名称匹配的资源

No resource found that matches the given name

这是我的(相关)XML代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<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>

我在上面提到的行上遇到了错误。告诉我

No resource found that matches the given name (at 'layout_below' with value '@id/whiteBackground').

我不确定为什么会发生这种情况,因为您可以看到ID /元素正好位于记录在其下方的位置。如您所见,下面的其他2个按钮也使用相同的layout_below="@id/whiteBackground",并且那里没有错误。这只是1行。

如果有人可以告诉我发生了什么,那将不胜感激。

谢谢


您可以更改

1
layout_below="@id/whiteBackground"

1
layout_below="@+id/whiteBackground"

我希望它会希望你!


在您的代码中尝试。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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>
  • 在xml代码的根目录中添加高度和宽度。

    1
    2
    3
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
  • 确保ID存在。

    1
     android:layout_below="@+id/image_text_editor"