2017-10-07 170 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" 
    
相關問題