0

Upon starting my game, the game does not utilise the entire android screen. This only happens with the game itself, shown by the image as the user is unable to reach the bottom of the screen. Have tried to find a solution however all attempts I have tried seems not to work. Unsure which code to supply, and therefore do not want to provide a large amount of code. Let me know which code to post. Any help would be appreciated.

Image of game

package com.example.spaceattack;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity
{
    private SpaceShipView gameView;
    private Handler handler = new Handler();
    private final static long Interval = 30;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        gameView = new SpaceShipView(this);
        setContentView(gameView);

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run()
            {
                handler.post(new Runnable() {
                    @Override
                    public void run()
                    {
                        gameView.invalidate();

                    }
                });
            }
        }, 0, Interval);

    }
}
Ryan Reynolds
  • 25
  • 1
  • 6
  • have a look at below question. You have to flag your activity as a full screen activity. https://stackoverflow.com/questions/2868047/fullscreen-activity-in-android – Deshan Apr 12 '20 at 04:25

1 Answers1

0

You need to hide the status/system by getting the window of your app and set below flags:

More from Documentation

// hide status bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

} else {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

So in your code:

public class MainActivity extends AppCompatActivity
{
    private SpaceShipView gameView;
    private Handler handler = new Handler();
    private final static long Interval = 30;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        gameView = new SpaceShipView(this);
        setContentView(gameView);

        // hide status bar
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mUiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            getWindow().getDecorView().setSystemUiVisibility(mUiOptions);
        } else {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run()
            {
                handler.post(new Runnable() {
                    @Override
                    public void run()
                    {
                        gameView.invalidate();

                    }
                });
            }
        }, 0, Interval);

    }
}
Zain
  • 37,492
  • 7
  • 60
  • 84