gpt4 book ai didi

java - Android Studio 游戏不使用整个 Android 显示屏

转载 作者:行者123 更新时间:2023-12-01 17:34:35 35 4
gpt4 key购买 nike

开始游戏后,游戏不会使用整个 Android 屏幕。这种情况仅发生在游戏本身中,如图像所示,因为用户无法到达屏幕底部。已尝试找到解决方案,但我尝试过的所有尝试似乎都不起作用。不确定要提供哪个代码,因此不想提供大量代码。让我知道要发布哪个代码。任何帮助,将不胜感激。

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);

}
}

最佳答案

您需要通过获取应用程序的窗口并设置以下标志来隐藏状态/系统:

更多来自 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);
}

所以在你的代码中:

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);

}
}

关于java - Android Studio 游戏不使用整个 Android 显示屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61062621/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com