setBackgroundResource()涵盖屏幕内容

时间:2019-01-29 12:15:41

标签: java android

我是android游戏编程的新手,我似乎无法找到一种方法来使背景图像保持在游戏背后,我没有用于此活动的xml文件,因此我在Java中添加了背景代码,但它涵盖了整个游戏。

预先感谢

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        _game = new Game(this);
     // _game.setBackgroundResource(R.drawable.background_ingame);
        setContentView(_game);

    }

1 个答案:

答案 0 :(得分:0)

GameView。如果您在游戏对象上调用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);
}
相关问题