簡體   English   中英

找不到與給定名稱匹配的資源,即使該資源存在

[英]No resource found that matches the given name even though it exist

我有一個android相對布局

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <com.my.view.text.MyTextView
        style="@style/textOnBg"
        android:layout_toLeftOf="@id/SkipIcon2"
        android:text="Skip"
        android:textStyle="normal" />

    <ImageView
        android:id="@+id/SkipIcon2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/signup_skip_icon" />
</RelativeLayout>

我怎么會得到這個錯誤:

error: Error: No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/ SkipIcon2').

嘗試這個..

android:layout_toLeftOf="@+id/SkipIcon2"您錯過了@+id

 <com.my.view.text.MyTextView
        style="@style/textOnBg"
        android:layout_toLeftOf="@+id/SkipIcon2"
        android:text="Skip"
        android:textStyle="normal" />

好吧,這取決於上下文,當您使用android:id的XML屬性時,您要指定一個新的id ,並指示解析器(或稱其為構建器)在R.java創建新條目R.java ,因此您必須包含一個+號。

您正在嘗試使用R.id中尚未聲明的ID。 您可以相互切換視圖或

<com.my.view.text.MyTextView
    style="@style/textOnBg"
    android:layout_toLeftOf="@+id/SkipIcon2"
    android:text="Skip"
    android:textStyle="normal" />

<ImageView
    android:id="@id/SkipIcon2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/signup_skip_icon" />

由於ID是最終的且是靜態的,因此您可以確定它只會被初始化一次

您要在聲明SkipIcon2之前引用它。 將引用更改為

    android:layout_toLeftOf="@+id/SkipIcon2"

嘗試這個

 @+id/SkipIcon2 

代替

@id/SkipIcon2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM