ste*_*sen 92 xml eclipse android
好的,所以这开始真的让我恼火.此错误以非常特殊但不太合理的方式弹出.
首先我要说的是,我已经查看了有关此错误的其他问题,谷歌也是这样.据我所知,大多数类似问题的出现是因为人们引用的String
资源或不在同一布局文件中的其他内容,他们错误地放置了"@ id +"中的"+"或类似的东西.
我遇到的问题出现在布局.xml文件中RelativeLayout
.这包含一个TableLayout
,两个LinearLayout
包含一些文本,最后一个ProgressBar
.我想要的是进度条与相对布局android:layout_alignParentBottom="true"
对齐,然后对齐进度条上方的两个线性布局(底部线性布局在进度条上方对齐,另一个在底部线性布局上方对齐).
它应该足够简单,看起来好像有效,即图形视图显示了所需的结果.但是,问题就出现了,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>
Run Code Online (Sandbox Code Playgroud)
请帮忙,我不知道是什么导致了这个错误!
Shrikant提供了在布局文件中更改外观顺序的解决方案,以便元素仅引用在读取引用时已定义的其他元素.
此外,由于其他人发布,更改@id/
到@+id/
,即使是在参考,不删除错误信息.正如Marco W.在这个帖子中所写的那样,事情是你必须@+id/
在第一次使用每个id时使用然后使用@id/
,即使第一次可能不是定义.
我完成了大部分设计并在Eclipse的图形编辑器中设置了引用的id,因此自动插入了导致错误消息的代码.也许这是Eclipse中的一个错误.
jee*_*eet 85
更改
@id/LinearLayout_acc
Run Code Online (Sandbox Code Playgroud)
至
@+id/LinearLayout_acc
Run Code Online (Sandbox Code Playgroud)
Shr*_*ant 77
请检查以下代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/LinearLayout_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/LinearLayout_acc"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FIRST" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SECOND" />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/ProgressBar_statusScreen"
android:layout_centerHorizontal="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="THIRD" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FOURTH" />
</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>
Run Code Online (Sandbox Code Playgroud)
另请检查以下链接.它说android:layout_below ="@ id/myTextView"将无法识别具有id"myTextView"的元素,如果它是在你使用它的元素之后写的.
Aka*_*shG 15
无论何时定义或引用id,都要将每个id更改@id
为@+id
.有了这个,你就不会得到
Android xml错误:"找不到与给定名称匹配的资源"和RelativeLayout(@ id/LinearLayout_acc,@ id/ProgressBar_statusScreen).