I have just started learning Android. To start with,I just wanted to create a Calculator application similar to what we get in stock android phones. I used the following layouts:
- Vertical Layout contining two rows which are:
- Text view to display the result as a horizontal layout
- Horizontal layout with two columns:
- Table layout containing buttons 0-9, '.' and '=' with 3 buttons in each row
- Table layout containing DEL, + , - , x and / buttons.
I want proper alignment of 4 rows of the first table layout and 5 rows of the second table layout. Shall I remove the padding space? Or do I need to manually set the minimum size of the buttons? Are the layouts set by me correct?
`
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="112dp"
android:id="@+id/textView" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true">
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:text="7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button7" />
<Button
android:text="8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button8" />
<Button
android:text="9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button9"
android:elevation="0dp" />
</TableRow>
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button4" />
<Button
android:text="5"
android:id="@+id/button5"
android:layout_height="match_parent" />
<Button
android:text="6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button6" />
</TableRow>
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button1" />
<Button
android:text="2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button2" />
<Button
android:text="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button3" />
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:text="."
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/buttonDot"
android:minHeight="48dp" />
<Button
android:text="0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button0" />
<Button
android:text="="
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/buttonequals"/>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:text="DEL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonDelete" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:text="/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonDivide" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:text="x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonMultiply" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonPlus" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:text="-"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonSubtract" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
`
Below code can do the job i guess,