本文介绍了(找不到ID引用)没有资源与给定名称相匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在相对布局中有以下内容.

I have the following inside a relative layout.

<TextEdit
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/buttonA"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@id/buttonA" />

<Button
    android:id="@+id/buttonA"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="@string/message" >
</Button>

Eclipse在行android:layout_alignBottom ="@ id/buttonA"和android:layout_toLeftOf ="@ id/buttonA"分别给了我这些错误:

Eclipse gives me these errors at lines android:layout_alignBottom="@id/buttonA" and android:layout_toLeftOf="@id/buttonA" respectively:

错误:错误:找不到与给定名称匹配的资源(在'layout_alignBottom'处,值为'@ id/buttonA').

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

错误:错误:找不到与给定名称匹配的资源(位于'layout_toLeftOf',值为'@ id/buttonA').

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

用@ + id/buttonA替换@ id/buttonA会删除此日食错误消息.这是正确的做法吗?如果是这样,那为什么会行得通呢? @ + id不会创建新的ID吗?我不要新的ID.我想使用按钮对象中引用的那个.最好的解决方法是什么?

Replacing @id/buttonA with @+id/buttonA removes this eclipse error message. Is that the right thing to do? If so, why would that work instead? Doesn't @+id create a new id? I don't want a new id. I want to use the one referenced in the button object. What is the best way to deal with this?

谢谢大家. -乔

推荐答案

使用@+id是正确的方法. @+id创建一个新的ID,但前提是该名称不存在.

Using @+id is the right way to do it. @+id creates a new id but only if one with that name doesn't already exist.

如果您不想这样做,对于这种特殊的简单情况,将TextEdit移动到Button下方就足够了.

If you don't want to do that, for this particular simple case it would suffice to move the TextEdit below the Button.

这篇关于(找不到ID引用)没有资源与给定名称相匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 01:37