Java 如何在画布上覆盖(Android)
如何在画布上覆盖按钮、文本等 我有一项活动:Java 如何在画布上覆盖(Android),java,android,xml,android-layout,Java,Android,Xml,Android Layout,如何在画布上覆盖按钮、文本等 我有一项活动: public class GameActivity extends AppCompatActivity { private GameView gameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gameView = new Game
public class GameActivity extends AppCompatActivity {
private GameView gameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView = new GameView(this, scrWidth, scrHeight);
setContentView(gameView);
}
}
使用以下活动\u游戏XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.exampl.proj.GameActivity">
</RelativeLayout>
我试图在XML中插入一个ImageButton,但它不会出现。我想这是因为setContentView关注gameView类
是否可以将ContentView设置为activity_game XML布局,并保持GameView运行,同时能够将参数传递给构造函数?在单个布局中创建一个包含GameView和所需其他视图的布局,然后将ContentView设置为该布局
public class GameView extends SurfaceView implements Runnable {