好的,所以这开始让我很恼火。这个错误以一种非常特殊、不太合乎逻辑的方式弹出。
首先让我说我已经查看了有关此错误的其他问题,谷歌也找到了。据我所知,大多数类似问题的发生是因为人们引用了 String
资源或不在同一布局文件中的其他内容,他们在“@id+”或类似内容中放错了“+”。
我遇到的问题出现在带有 RelativeLayout
的布局 .xml 文件中。这包含一个 TableLayout
、两个包含一些文本的 LinearLayout
,最后是一个 ProgressBar
。我想要的是使用 android:layout_alignParentBottom="true"
将进度条与相对布局对齐,然后在进度条上方对齐两个线性布局(底部线性布局在进度条上方对齐, 另一个在底部线性布局上方对齐)。
它应该足够简单并且看起来好像可以工作,即图形 View 显示了所需的结果。然而,问题来了,Eclipse 在两个线性布局上给了我一个错误,
“错误:未找到与给定名称匹配的资源(在 'layout_above' 处,值为 '@id/LinearLayout_acc')。”
对于其他线性布局引用进度条的相同错误。我已经检查了三次以上,没有错别字(ID 也存在于 packagename.R.java 中),并且我已经尝试清理项目十几次。
我在保存(和自动构建)时没有收到错误,直到我决定运行项目。另一个奇怪的事情是,当我从进度条而不是顶部线性布局引用底部线性布局时,我没有收到错误!
我的布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_activity" >
<TableLayout
... />
<LinearLayout
android:id="@+id/LinearLayout_dist"
android:layout_above="@id/LinearLayout_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<TextView
... />
<TextView
... />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout_acc"
android:layout_above="@id/ProgressBar_statusScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<TextView
... />
<TextView
... />
</LinearLayout>
<ProgressBar
android:id="@+id/ProgressBar_statusScreen"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp" />
</RelativeLayout>
请帮忙,我不知道是什么导致了这个错误!
用答案编辑
Shrikant 提供了更改布局文件中出现顺序的解决方案,以便元素仅引用在读取引用时已定义的其他元素。
此外,正如其他人发布的那样,将 @id/
更改为 @+id/
,即使在引用中,也会删除错误消息。正如 Marco W. 在 this 中所写线程,问题是您必须在第一次提到每个 id 时使用 @+id/
,然后再使用 @id/
,即使第一次可能不是一个定义。
我完成了大部分设计并在 Eclipse 的图形编辑器中设置了引用的 id,因此会自动插入导致错误消息的代码。也许这是 Eclipse 中的一个错误。
最佳答案
改变
@id/LinearLayout_acc
到
@+id/LinearLayout_acc
关于Android xml 错误 : "No resource found that matches the given name" with RelativeLayout (@id/LinearLayout_acc, @id/ProgressBar_statusScreen),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11668718/