Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am creating a simple game, Tic Tac Toe...

I'm starting with the interface. Can someone suggest on how can I make the button's perfect square. I have set the width depends on what is the screen size.
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.hansoctantan.tictactoe.Activity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Your Turn"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Player1: 0"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Player2: 0"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <Button
                android:id="@+id/button2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <Button
                android:id="@+id/button3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

        </LinearLayout>
    </LinearLayout>

</RelativeLayout>


I know java but started andriod yesterday.

Thanks

Additional
if there's a way/code in class that can do this, its also appreciated.

Thanks Again...
Posted
Updated 27-Aug-14 20:03pm
v5

1 solution

Have you ever try with to create the background shape for any buttons?

Check with below:

below is the separated image from your image of button.

![enter image description here][1]

Now, put that in your ImageButton as src like below:

android:src="@drawable/twitter"<pre>


Now, just create shape of the ImageButton to have black shader background.

android:background="@drawable/button_shape"


and the button_shape is the xml file in drawable resource:

    <shape>
        xmlns:android="http://schemas.android.com/apk/res/android">
        <stroke>
            android:width="1dp" 
            android:color="#505050"/>
        <corners>
          	android:radius="7dp" />
    
        <padding>
            android:left="1dp"
            android:right="1dp"
            android:top="1dp"
            android:bottom="1dp"/>
        
        <solid android:color="#505050" xmlns:android="#unknown" />
           
    </padding></corners></stroke></shape>


Just try to implement with this. Might above code needs to change some color value as per your requirement.

Let me know if its not work.


  Sandeep
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900