私はゲームに取り組み始めています。このゲームでは、基本的にロゴ/広告行、スコア行、およびゲーム行の3つのビューが積み重ねられます。まず、score_bar_layoutというXMLレイアウトを使用するLevel_Score_Barというクラスを作成しようとしています。現在、私のメインのXMLコードは次のようになっています(注:以下の提案に基づいてこれを編集しています。修正されたら、編集を停止します):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent" android:id="@+id/Title_bar">
<ImageView android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_width="wrap_content" android:src="@drawable/icon"></ImageView>
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/linearLayout4">
</LinearLayout>
</LinearLayout>
<pearsonartphoto.AJEG.Level_Score_bar android:layout_height="fill_parent" android:layout_width="wrap_content" android:id="@+id/Score_Bar">
</pearsonartphoto.AJEG.Level_Score_bar>
<LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" android:id="@+id/Game_Row">
<View android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/view3"></View>
</LinearLayout>
</LinearLayout>
Level_Score_bar.javaは次のようになります。
public class Level_Score_bar extends RelativeLayout {
public Level_Score_bar(Context context, AttributeSet set, int defStyle) {
this(context,set);
}
public Level_Score_bar(Context context, AttributeSet set) {
super(context, set);
this.addView(View.inflate(context,R.layout.score_bar_layout,null));
Log.d(TAG,"Added view");
}
}
score_bar_layout.xmlは次のようになります
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="@string/level" android:id="@+id/Level_text" android:layout_toRightOf="@+id/Level_text"></TextView>
<TextView android:id="@+id/Current_Level" android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:layout_alignParentTop="true"></TextView>
<TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:layout_centerVertical="false" android:layout_centerHorizontal="true" android:id="@+id/Time_Left"></TextView>
<TextView android:id="@+id/Score_Label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:text="@string/score"></TextView>
<TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:layout_toRightOf="@+id/Score_Label" android:id="@+id/Score_Value"></TextView>
</RelativeLayout>
問題は、ビューがまったく表示されないことです。私は何か小さなものが欠けていると確信していますが、私はそれを理解することができません。addViewコマンドが呼び出されていることを確認しました(Log.dステートメントを介して)が、違いがないようです...