How to properly mark the playing field, or as is usually done. And how to link this markup with the code. It is necessary that there are buttons at the bottom of the screen, support information at the top, gameplay in the middle. It may be easier to explain correctly than to try to correct what is already there.

This is my first game app. I tried to do the markup like this:

  1. Top panel - LinearLayout .
  2. In the middle of the playing field. It is a Round class that extends LinearLayout . It will be the main drawing of the application.
  3. Below the panel with buttons - LinearLayout .
    The GameProcessView class extends LinearLayout , it is responsible for periodic redrawing.

Some problems began to arise:
In the Round class, I need to get its boundaries, but they are all equal to zeros (if I get them in the constructor). The problem seemed to be solved when I overloaded the onSizeChanged(...) method, but when drawing in the resulting bounds (I checked them, they are correct) nothing is displayed. If in the constructor to write:

 setBackgroundColor(Color.CYAN); 

That drawing is happening, but as expected, the background image is filled.

 <com.pos.GameProcessView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gameView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/game_wall_paper" android:gravity="center_horizontal" android:orientation="vertical" > <LinearLayout android:id="@+id/topPanel" android:layout_width="fill_parent" android:layout_height="50dp" android:orientation="vertical" > </LinearLayout> <com.pos.Round android:id="@+id/gameField" android:layout_width="fill_parent" android:layout_height="50dp" android:layout_weight="0.28" android:gravity="bottom" android:orientation="horizontal" > </com.pos.Round> <LinearLayout android:id="@+id/bottomPanel" android:layout_width="fill_parent" android:layout_height="50dp" android:gravity="center|clip_horizontal" android:orientation="horizontal" > <ImageButton android:id="@+id/var1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/square" android:background="@color/buttonBackground"> <requestFocus /> </ImageButton> <ImageButton android:id="@+id/var2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/square" android:background="@color/buttonBackground"> </ImageButton> </LinearLayout> </com.pos.GameProcessView> 

    2 answers 2

    This is actually done by code, not by an .xml template. Here you need to call ItemMenu from pressing the Menu button.

    About the placement of objects on the screen and how the menu is made here

      To create games, it is better to read the book by Mario Zechner - Programming Games for Android, it’s pretty well told how to make a simple engine, and write a simple 2D game with information overlay \ buttons on the playing field (what interests you, and most importantly, understand how it's done) + Finalization of the engine for writing 3D games