2012-04-01 10 views
1

レイアウト内の別のコントロールのリソースIDを、カスタムコントロールの参照を使用してカスタムコントロールのコンストラクタから取得しようとしています。カスタムコントロール内のgetResourceIdは、Eclipse編集モードでデフォルト値を返します

コントロールは実行時に美しく動作しますが、エディタでは以下に示す例外がスローされます。

このコードは、SlideDrawerのAndroidソースから恥知らずにリッピングされていたので、動作しなければならないことが分かっています。間違っていることがあります。

カスタムコントロールのコンストラクタはこれを含んでいる...

mHandleId = a.getResourceId(R.styleable.Panel_handle, 0); 
    if (mHandleId == 0) { 
     e = new IllegalArgumentException(a.getPositionDescription() + 
       ": The handle attribute is required and must refer to a valid child."); 
    } 

レイアウトはIDが一度だけ定義することができたときにあなたが二回@+id/message_panel_handle@+id/message_panel_contentを定義している。この

<com.xenosoft.hunted.widgets.Panel 
    xmlns:app="http://schemas.android.com/apk/res/com.xenosoft.hunted" 
    android:id="@+id/message_panel" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    app:handle="@+id/message_panel_handle" 
    app:content="@+id/message_panel_content" 
    app:position="left" 
    > 

    <ImageView 
     android:id="@+id/message_panel_handle" 
     android:layout_width="50dp" 
     android:layout_height="fill_parent" 
     android:background="#FF0000"> 

    </ImageView> 

    <LinearLayout 
     android:id="@+id/message_panel_content" 
     android:layout_width="200px" 
     android:layout_height="fill_parent" 
     android:background="#000000"> 
     </LinearLayout> 

</com.xenosoft.hunted.widgets.Panel> 
+0

これを理解したかどうかわかりませんが、このコードはいつでもisInEditMode()に入れましたか? – Shubhayu

答えて

0

のように見えます。 RelativeLayoutを使用してビューを配置する方法を参照してください。

<com.xenosoft.hunted.widgets.Panel 
    xmlns:app="http://schemas.android.com/apk/res/com.xenosoft.hunted" 
    android:id="@+id/message_panel" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    app:handle="@+id/message_panel_handle" 
    app:content="@+id/message_panel_content" 
    app:position="left" 
    > 

    <ImageView 
    android:id="@id/message_panel_handle" 
    android:layout_width="50dp" 
    android:layout_height="fill_parent" 
    android:background="#FF0000"> 

    </ImageView> 

    <LinearLayout 
    android:id="@id/message_panel_content" 
    android:layout_width="200px" 
    android:layout_height="fill_parent" 
    android:background="#000000"> 
     </LinearLayout> 

</com.xenosoft.hunted.widgets.Panel> 
関連する問題