我有以下课程
public class GameActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View gameView = new GameView(this);
setContentView(gameView);
}
}
现在我想向我的 GameView 类添加一个 Button。
public GameView(Context context) {
super(context);
// Code ...
}
我在游戏过程中需要这个按钮,因此它应该始终位于我正在绘制的所有其他画布的前面。
我怎样才能做到这一点?
您想创建一个新按钮吗?
Button b = new Button(context);
b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
gameView.addView(b);
Use ViewGroup
as GameView
父视图而不是简单的视图
ViewGroup gameView = new GameView(this);
public class GameView extends ViewGroup { //...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)