これは一般に認められている方法ですか?私のホーム画面は、以下のコードを使用して、まず下の画像のように見え、ユーザーにゲームを開始するよう促します。Android XMLレイアウトレイヤー化
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.snake.SnakeView
android:id="@+id/snake"
android:layout_width="match_parent"
android:layout_height="match_parent"
tileSize="24" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/text"
android:text="@string/snake_layout_text_text"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textColor="#ff8888ff"
android:textSize="24sp"/>
</RelativeLayout>
</FrameLayout>
これはエラーなしで働いていたが、私は最後の5得点(ボタン)、ユーザの入力(のEditText)とショーのためにアイテムを追加するために必要なむしろを通じてプレーヤーを置くよりも、その下にこのプロンプトを望んでいました複数の画面。私が読んだところでは、競合のないRelativeLayoutの中にFrameLayoutを埋め込むことができるはずですが、Show Scoresボタンにしか作用せず、ゲームのプロンプトが表示されません。デザインビューでチェックすると、下半分(現在表示中)がゲームをプレイできるクラスをインスタンス化できないというエラーが表示されます。私は単にこれを修正する方法について私自身の傍にいて、将来のプロジェクトでこれが再び起こらないように、間違ったことを理解したいと思います。以下は、エラーを引き起こす変更されたコードです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:id="@+id/textViewName"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editTextName"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/buttonStyleSmall"
android:text="Add"
android:id="@+id/btnAdd"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last 5 Games"
android:id="@+id/btnLastFive"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.snake.SnakeView
android:id="@+id/snake"
android:layout_width="match_parent"
android:layout_height="match_parent"
tileSize="24" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/text"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textColor="#ff8888ff"
android:textSize="24sp"/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
したがって、提案されたレイアウトとまったく同じに見えるレイアウトをしたいですか?または、あなたが望むのは、提案されたレイアウトを表示するために大きな青いラベル「Snake press up to play」をクリックしたときです。 –
はい。提案されたレイアウトは、Android Studioでデザインビューが現在示しているものです。理論上のホーム画面は、下半分がオリジナルに表示されているものを表示しているように、まったく同じように表示されます。 –
'com.example.android.snake.SnakeView'の内容(「現在表示されている下半分がゲームをプレイできるクラスをインスタンス化できないというエラーが表示されています」) ?もう1つの質問は、ユーザーが「再生を押してください」をクリックするとラベルが消え、「com.example.android.snake.SnakeView」だけが表示されるようにします。 –