2017-10-07 169 views
1

这里是我的(相关)XML代码:没有资源发现匹配给定名称

<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

尝试'@ + id'你第一次引用它(读从上到下)和'@ id'之后每次。 – stkent

+0

非常感谢你@stkent我猜这只是发生在相关布局中的东西 –

+0

它发生在RelativeLayout的更常见的情况是,但它不是唯一的! – stkent

回答

2

您可以更改

layout_below="@id/whiteBackground" 

layout_below="@+id/whiteBackground" 

我希望它会希望你!

1

在您的代码中试试这个。

<?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代码的根。

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

    android:layout_below="@+id/image_text_editor" 
    
相关问题