Best way to add a textview to your main game view?

I am currently developing a simple game for Android, where the main action takes place in my GameView class, which is just an extension of View.

I want to add some text showing the rating in the upper left corner of my GameView, and would like to know a better way to implement this?

Thanks in advance

Matt Drewrier

+3
source share
2 answers

I assume your GameView has a canvas since it draws graphics, right? In this case, when you do the rest of your drawing, use

//canvas.drawText(String text, float x, float y, Paint paint); this is the actual method
canvas.drawText(score, 5, 5, null); //but yours would look more like this

Then you just need to create a “score” line and update it in the game.

Alternatively, you can try addView (View child). It will look like this:

GameView.addView(TextView);
+5

, Hexaddicus, , , . "", , . , , , .

Android UI .

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/control_pane"
    android:layout_width="fill_parent" 
    android:layout_height="48dip"
    android:layout_alignParentBottom="true">
</FrameLayout>
<com.sharpermindstech.android.hexaddicus.opengl.views.HexBoardView
    android:id="@+id/gamefield" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_above="@id/control_pane" />
</RelativeLayout>
+2

Source: https://habr.com/ru/post/1795778/


All Articles