我是android游戏编程的新手,我似乎无法找到一种方法来使背景图像保持在游戏背后,我没有用于此活动的xml文件,因此我在Java中添加了背景代码,但它涵盖了整个游戏。
预先感谢
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_game = new Game(this);
// _game.setBackgroundResource(R.drawable.background_ingame);
setContentView(_game);
}
答案 0 :(得分:0)
Game
是View
。如果您在游戏对象上调用setBackgroundResource
,它将被设置为游戏背景。它将根据Game
视图的大小进行缩放。
如果要将背景设置为屏幕,则Game
将位于layer的上方。您可以尝试这样的事情:-
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frameLayout=new FrameLayout(this);
frameLayout.setBackgroundResource(R.drawable.background_ingame);
game = new Game(this);
frameLayout.addView(game);
setContentView(frameLayout);
}