Im trying to make a tic-tac-toe game(android version). I want to make all the 9 buttons auto-sizing regarding to the width and the height of the device and put them evenly in a 3*3 grid. But I can only set the number for their sizes now. Can anyone tell me how to let them use the height and width of the parent and calculate their sizes?
Also, im using the grid layout now. Is this the best layout I should use for the tic-tac-toe game?
Thanks.
Use LinearLayouts
with android:weightSum
and android:layout_weight
Edit
Example :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3" >
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3" >
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3" >
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With