0

これが私の問題です。

現在、TicTacToe-Game の相対レイアウトを設定しています。これは、9 つ​​の ImageButton と、グリッドを取得するために使用する 8 つのビューで構成されています。

「リソースが見つかりません」というエラーが xmlfile にある (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 ファイルの「間違い」を修正し、プロジェクトをクリーンアップし、再度ビルドしました。何も機能しませんでした。

4

2 に答える 2

0

あなたの最初の見方から、私はこのような多くの問題を見ます:

<View 
    android:layout_width="5dp" 
    android:layout_height="160dp"
    android:background="#FF0000"
    android:layout_toLeftOf="@id/hor2"
    android:id="@+id/vert1"
    />

hor2まだ宣言されていない場合は、以下を使用する必要があります@+id

    android:layout_toLeftOf="@+id/hor2"

適切な表記を使用するには、これらすべてを更新する必要があります。

于 2012-11-27T18:12:02.680 に答える
0

サムは正しい方向に進んでいますが、属性 @+id/を設定していないときは、実際にはユーザーにとって悪い習慣です。R ファイルがまだ存在しない場合は、実際にその ID を R ファイルに追加しようとします。これにより、別の要素が基づいて配置される要素を削除するという問題が発生する可能性がありますが、使用しているためエラーはスローされませんandroid:id@+id/@+id/

代わりに、それらに基づいて整列するビューの上のレイアウトを xml ファイルで定義する必要があります。たとえば、winners以下に移動する必要がありますanotherGame

<Button
    android:id="@+id/anotherGame"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/winners"
    android:text="@string/newGameButton"
    android:visibility="invisible" />

<TextView
    android:id="@+id/winners"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="@string/winner"
    android:textColor="#FFFFFF" />

すべてのビューをそれらに基づいて整列するビューの上で宣言することを絶対に避けられない場合は、使用に頼ることができます@+id/

于 2012-11-27T18:31:59.553 に答える