日々是好日~every day is a good day~

日常の中の非日常の備忘録

【Android Studio】もぐらたたき 2回目

今日は『ゲーム画面のレイアウト(XML)作成』です

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="@drawable/moguragrass"
    tools:context=".MainActivity">

    <SurfaceView
        android:id="@+id/surfaceView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <LinearLayout
        android:id="@+id/relativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:orientation="horizontal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"
            android:text="Score:"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/tvScore"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right|left"
            android:text="0"
            android:textSize="30sp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"
            android:text="Time:"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/tvTimer"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right|left"
            android:text="30"
            android:textSize="30sp" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/ImgbtStart"
        android:layout_width="130dp"
        android:layout_height="70dp"
        android:background="@drawable/btnstart"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        tools:ignore="ButtonStyle,ContentDescription,SpeakableTextPresentCheck" />

</androidx.constraintlayout.widget.ConstraintLayout>


ゲーム画面のレイアウトができました
もぐらはSurfaceViewを使って表示します
SurfaceViewは通常のViewより高速に描画する仕組みです
Viewでもやってみたのですが 処理の遅延が気になるレベルだったのでSurfaceViewに変更しました
明日からはkotlinです