Reputation: 21
How can I overlay buttons, text, etc. on top of a canvas?
I have an activity:
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);
}
}
with the following activity_game 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>
All the drawing happens in the GameView class.
public class GameView extends SurfaceView implements Runnable {
I tried to put in an ImageButton in the XML but it wouldnt appear I guess it's because setContentView focuses on gameView class.
Is it possible to setContentView to the activity_game XML layout and keep the GameView running with the ability to pass the params to the constructor?
Upvotes: 1
Views: 430
Reputation: 93708
Create a layout with a GameView and the other views you want in a single layout, then setContentView to that layout.
Upvotes: 1