找不到与给定名称匹配的资源,即使该资源存在



我有一个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.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

最新更新