初めて作ったゲーム
(再生できなくなっていたので2024.2.5に修正しました)
1から25まで順番にタッチしていくゲームです
これを製作順にアップしていきます
- レイアウト(XML)作成
- 数字をシャッフルして表示
- カウントダウンして数字をタップできるようにする
- タイマーを表示する
- リトライor終了(ダイアログアラート)
- 効果音をつける
今日は『レイアウト(XLM)の作成』です
<?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" tools:context=".MainActivity"> <TableLayout android:layout_width="0dp" android:layout_height="0dp" android:layout_marginTop="110dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn1" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="1" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn2" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="2" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn3" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="3" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn4" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="4" android:textSize="20sp" app:backgroundTint="#F46257"/> <Button android:id="@+id/btn5" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="5" android:textSize="20sp" app:backgroundTint="#F46257" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn6" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="6" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn7" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="7" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn8" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="8" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn9" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="9" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn10" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="10" android:textSize="20sp" app:backgroundTint="#F46257" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn11" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="11" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn12" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="12" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn13" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="13" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn14" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="14" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn15" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="15" android:textSize="20sp" app:backgroundTint="#F46257" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn16" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="16" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn17" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="17" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn18" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="18" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn19" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="19" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn20" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="20" android:textSize="20sp" app:backgroundTint="#F46257" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn21" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="21" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn22" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="22" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn23" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="23" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn24" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="24" android:textSize="20sp" app:backgroundTint="#F46257" /> <Button android:id="@+id/btn25" style="@style/Widget.AppCompat.Button" android:layout_width="0dip" android:layout_height="90dp" android:layout_weight="1" android:text="25" android:textSize="20sp" app:backgroundTint="#F46257" /> </TableRow> </TableLayout> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv" android:layout_width="0dip" android:layout_height="90dp" android:layout_marginTop="8dp" android:layout_weight="3" android:text="" android:textSize="48sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/tvCD" android:layout_width="0dip" android:layout_height="90dp" android:layout_marginTop="8dp" android:layout_weight="1" android:text="3" android:textSize="48sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </TableRow> </androidx.constraintlayout.widget.ConstraintLayout>
レイアウトができました