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:
- Top panel -
LinearLayout
. - In the middle of the playing field. It is a
Round
class that extendsLinearLayout
. It will be the main drawing of the application. - Below the panel with buttons -
LinearLayout
.
TheGameProcessView
class extendsLinearLayout
, 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>