【发布时间】:2012-11-27 17:57:31
【问题描述】:
这是我的问题。
我目前正在为井字游戏设置相对布局。 它由 9 个 ImageButtons 和 8 个用于获取网格的 Views 组成。
要么我的 xml 文件中有错误,说“找不到资源”(即使 id 已正确构建到我的 r.class 中),要么当我将布局引用重新输入到其他视图时错误消失。但是如果我重新输入它,清理项目并重新构建它,eclipse 会让我的 R.class 消失。
这是我的 XML 文件:
`<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/notepad2" >
<View
android:layout_width="5dp"
android:layout_height="160dp"
android:background="#FF0000"
android:layout_toLeftOf="@id/hor2"
android:id="@+id/vert1"
/>
<View
android:layout_width="5dp"
android:layout_height="160dp"
android:background="#FF0000"
android:layout_toLeftOf="@id/hor3"
android:id="@+id/vert2"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld4"
android:layout_above="@id/feld4"
android:id="@+id/hor1"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld5"
android:layout_above="@id/feld5"
android:id="@+id/hor2"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld6"
android:layout_above="@id/feld6"
android:id="@+id/hor3"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld4"
android:layout_below="@id/feld4"
android:id="@+id/hor4"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld5"
android:layout_below="@id/feld5"
android:id="@+id/hor5"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld5"
android:layout_below="@id/feld6"
android:id="@+id/hor6"
/>
<ImageButton
android:id="@+id/feld1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toLeftOf="@id/vert1"
android:layout_alignTop="@id/vert1"
/>
<ImageButton
android:id="@+id/feld2"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_above="@id/hor2"
android:layout_alignLeft="@id/hor2"
/>
<ImageButton
android:id="@+id/feld3"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert2"
android:layout_alignTop="@id/vert2"
/>
<ImageButton
android:id="@+id/feld4"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toLeftOf="@id/vert1"
android:layout_alignTop="@id/feld5"
/>
<ImageButton
android:id="@+id/feld5"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_centerInParent="true"
/>
<ImageButton
android:id="@+id/feld6"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert2"
android:layout_alignTop="@id/feld5"
/>
<ImageButton
android:id="@+id/feld7"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toLeftOf="@id/vert1"
android:layout_below="@id/hor4"
/>
<ImageButton
android:id="@+id/feld8"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert1"
android:layout_below="@id/hor4"
/>
<ImageButton
android:id="@+id/feld9"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert2"
android:layout_below="@id/hor4"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/winners"
android:text="@string/winner"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/anotherGame"
android:visibility="invisible"
android:layout_above="@id/winners"
android:text="@string/newGameButton"
/>
`
有人知道如何解决吗?
我已经试过了。更正了 xml 文件中的“错误”,清理了项目,重新构建了它等等。没有任何效果。
【问题讨论】:
-
究竟是什么错误?你能发布控制台构建信息吗?
-
哪些资源找不到?一两个还是一个都没有?
-
'[2012-11-27 18:28:11 - TicTacToe] XML 文件中的错误:正在中止构建。 [2012-11-27 18:29:27 - TicTacToe] XML 文件中的错误:正在中止构建。而 r 类可用。尽管 id 已经在 r 类中,但错误都是“无法解析资源”。
-
无法解析资源@id/hor2 无法解析资源@id/feld2 无法解析资源@id/vert1 无法解析资源@id/feld4 无法解析资源@ id/feld5 无法解析资源@id/vert2 无法解析资源@id/feld6 无法解析资源@id/hor4 无法解析资源@id/winners 是具有r 类时的错误。没关系,因为它们显然不是写在 r 类中的。所以我尝试清理项目和构建项目,因为如果 R 中缺少资源,我通常会这样修复它。但不是添加这个资源,R 消失了。
标签: android xml r.java-file