2016-05-16 11 views
1

3つのフラグメントを構成しようとしています:残りのすべてのスペースを取ることになる中間に1つ。指定された名前と一致するリソースが見つかりません(値 '@ id/right_item_menu_fragment'を持つ 'layout_toRightOf')

「layout_toRightOf」の値が「0」の特定の名前と一致するリソースが見つかりませんでしたが、私は解決策を探して、私がオンラインで見つけた提案に従いました。 @ id/right_item_menu_fragment ')。

レイアウトid = 'right_item_menu_fragment'の後にRelativeLayout id = 'canvas_fragment'を移動すると、インストールは成功します(上述のエラーはありません)。ただし、 'canvas_fragment'は画面に表示されません。

私はこのエラーを検索しましたが、それは起こり得るさまざまな理由がありますが、私の状況には該当しません。 Eclipseを使用すると多くの人にこのエラーが発生しますが、Androidスタジオを使用しています。

私が間違っていることを誰かが指摘できれば、大いに助けになるでしょう。

は、ここに私のレイアウトです:私はこの前に実行した

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
  
android:id="@+id/canvas_layout"
  
android:layout_width="match_parent"
  
android:layout_height="match_parent">
 
  

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
  
    android:id="@+id/left_item_menu_fragment"
  
    android:layout_width="@dimen/item_menu_width"
  
    android:layout_height="match_parent"
  
    android:layout_alignParentLeft = "true"
  
    android:background="#cccccc">
 
  

</RelativeLayout>
 
  

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
  
     android:id="@+id/canvas_fragment"
  
     android:orientation="vertical"
  
     android:layout_height="match_parent"
  
     android:layout_width="match_parent" 

   android:layout_toLeftOf = "@+id/left_item_menu_fragment"
  
     android:layout_toRightOf = "@id/right_item_menu_fragment"
  
     android:background="#000000" >
 
  

</RelativeLayout>
 
 
  

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
  
     android:id="@+id/right_item_menu_fragment"
  
     android:layout_width="@dimen/item_menu_width"
  
     android:layout_height="match_parent"
  
     android:layout_alignParentRight = "true"
  
     android:background="#cccccc">
 
  

</RelativeLayout> 

 
 
 
 
 </RelativeLayout> 

+0

'id'の前に' + 'を追加します。つまり、 '' @ + id/right_item_menu_fragment ''です。その順序であなたのレイアウトでは、そのIDはまだ生成されていません。これは '+'のものです。 –

答えて

1

、前方参照の問題のようです。相対レイアウトを次のように並べ替えると、中央のセクションが最後に定義されます。マイクMが言う

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/canvas_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<RelativeLayout 
    android:id="@+id/left_item_menu_fragment" 
    android:layout_width="@dimen/item_menu_width" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:background="#cccccc"> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/right_item_menu_fragment" 
    android:layout_width="@dimen/item_menu_width" 
    android:layout_height="match_parent" 
    android:layout_alignParentRight="true" 
    android:background="#cccccc"> 

</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/canvas_fragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    <!-- layout_toLeftOf and layout_toRightOf were backwards. This is correct.--> 
    android:layout_toLeftOf="@id/right_item_menu_fragment" 
    android:layout_toRightOf="@id/left_item_menu_fragment" 
    android:background="#000000" 
    android:orientation="vertical"> 
</RelativeLayout> 

も同様に当てはまります。詳細は、this linkを参照してください。

+0

私はそれを試して、 "canvas_fragment"は画面にも表示されませんでした。左右の断片だけ。しかし、体重を使って表示する方法を見つけました。私は外側のレイアウトをandroid:weightSum = "10"と定義し、それぞれのフラグメントに対応するlayout_weightsを1と9と1に与えました。 –

+0

'canvas_fragment'が' left_item_menu_fragment'の左に、 'right_item_menu_fragment'の中にあり、それは後方です。 'left_item_menu_fragment'の左側と' left_item_menu_fragment'の右側に配置する必要があります。同意しますか?見落とすのは簡単です。 – Cheticamp

+0

ありがとう、@Cheticamp、それはcanvas_fragmentが表示されなかった理由です。それは今働いている。 –

関連する問題