Android GridLayout cutting off - android

I'm following this tutorial: http://code.tutsplus.com/tutorials/android-user-interface-design-creating-a-numeric-keypad-with-gridlayout--mobile-8677
But in my application, I'm getting the result:
I mean, the buttons are being cutted off of the screen.
The XML is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
android:orientation="vertical"
tools:context=".AtividadePrincipal">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnCount="4"
android:orientation="horizontal" >
<Button
android:layout_column="3"
android:text="/" />
<Button android:text="1" />
<Button android:text="2" />
<Button android:text="3" />
<Button android:text="*" />
<Button android:text="4" />
<Button android:text="5" />
<Button android:text="6" />
<Button android:text="-" />
<Button android:text="7" />
<Button android:text="8" />
<Button android:text="9" />
<Button
android:layout_gravity="fill"
android:layout_rowSpan="3"
android:text="+" />
<Button
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:text="0" />
<Button android:text="00" />
<Button
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:text="=" />
</GridLayout>
</LinearLayout>

android:layout_width="0dp"
android:layout_height="wrap_content"
<android.support.v7.widget.GridLayout>
......
<Spinner
android:id="#+id/area"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="32dp"
android:prompt="#null"
app:layout_column="1"
app:layout_gravity="center_vertical|fill_horizontal"
app:layout_row="2" />
</android.support.v7.widget.GridLayout>
`

Related

Grid layout extra space

I am trying to make an android Calculator app but however i am stuck on one thing, there is some extra space coming up while using grid layout.
Now i know i have used match parent value for the layout height and width which might be the reason for the extra spacing in the image.
Since , i am new to android and i am just learning more and more of android, could anyone let me know , how can i evenly distribute those buttons on the grid layout?
Code
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.tilak.myfirstapplication.MainActivity">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:height="225dp"
android:ems="10"
android:layout_gravity="fill_horizontal"
android:inputType="textMultiLine"
tools:layout_editor_absoluteX="104dp"
tools:layout_editor_absoluteY="207dp" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="5"
android:columnCount="4"
android:background="#ff0000"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_row="0"
android:layout_column="0"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="100dp" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_row="0"
android:layout_column="1"
tools:layout_editor_absoluteX="116dp"
tools:layout_editor_absoluteY="289dp" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_row="0"
android:layout_column="2"
tools:layout_editor_absoluteX="129dp"
tools:layout_editor_absoluteY="255dp" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_row="0"
android:layout_column="3"
tools:layout_editor_absoluteX="41dp"
tools:layout_editor_absoluteY="180dp" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_row="1"
android:layout_column="0"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="259dp" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:text="Button" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_row="1"
android:layout_column="2"
tools:layout_editor_absoluteX="129dp"
tools:layout_editor_absoluteY="217dp" />
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="3"
android:text="Button"
tools:layout_editor_absoluteX="129dp"
tools:layout_editor_absoluteY="168dp" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:text="Button" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="1"
android:text="Button" />
<Button
android:id="#+id/button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="2"
android:text="Button" />
<Button
android:id="#+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="3"
android:text="Button" />
<Button
android:id="#+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="0"
android:text="Button" />
<Button
android:id="#+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="1"
android:text="Button" />
<Button
android:id="#+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="2"
android:text="Button" />
<Button
android:id="#+id/button19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="3"
android:text="Button" />
<Button
android:id="#+id/button20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="0"
android:text="Button" />
<Button
android:id="#+id/button21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="1"
android:text="Button" />
<Button
android:id="#+id/button22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="2"
android:text="Button" />
<Button
android:id="#+id/button23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="3"
android:text="Button" />
</GridLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
I suggest using the weight attribute to make the child views share the space equally. There's another post here on StackOverflow with a great answer that covers the subject:
https://stackoverflow.com/a/30245753/2281718
In short, just set the width to 0dp and add the android:layout_columnWeight="1" for all children
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
...
/>
Use place holder like this.
This is not exact XML.
<button 1/>
<textview weight=1>
<button 2/>
<textview weight=1>
<button 3/>
<textview weight=1>
<button 4/>

How to layout my android application?

I am writing a math application for my daughter. It shall consist of upper row with assignment to solve, some progress bar and then keypad on left and function pad on right. This is my idea:
I started with a linear layout holding set of linear layouts. Android studio argues that nested weights have bad performance. And I failed to have 4 rows of keypad besides 5 rows of functions. This is my current progress:
Then I used a table layout but it does not have row span. So I switched to a relative layout, but I failed to distribute rows evenly. The last attempt was grid layout, but again I cannot distribute the rows evenly.
Any idea, how to achieve my goal?
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".CalcActivity"
android:columnCount="5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:useDefaultMargins="true"
android:orientation="horizontal">
<TextView
android:layout_gravity="fill_horizontal|center_vertical"
android:text="1"
android:id="#+id/firstOperand"
style="#style/KeypadButton"
android:layout_column="0"
android:layout_row="0" />
<TextView
android:text="+"
android:id="#+id/operator"
style="#style/KeypadFunctionButton"
android:layout_column="1"
android:layout_row="0"
android:layout_gravity="fill_horizontal|center_vertical"
/>
<TextView
android:text="1"
android:id="#+id/secondOperand"
style="#style/KeypadButton"
android:layout_column="2"
android:layout_row="0"
android:layout_gravity="fill_horizontal|center_vertical"
/>
<TextView
android:text="="
android:id="#+id/equalView"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadFunctionButton"
android:layout_column="3"
android:layout_row="0" />
<TextView
android:text="2"
android:id="#+id/resultView"
style="#style/KeypadButton"
android:layout_column="4"
android:layout_row="0"
android:layout_gravity="fill_horizontal|center_vertical"
/>
<SeekBar
android:id="#+id/seekBar"
android:layout_gravity="fill_horizontal|center_vertical"
android:onClick=""
android:layout_row="1"
android:layout_columnSpan="4"
android:layout_column="0" />
<ImageView
android:id="#+id/progressImage"
android:layout_gravity="fill_horizontal|center_vertical"
android:src="#drawable/ic_action_cat"
android:layout_row="1"
android:layout_column="4" />
<LinearLayout
android:layout_gravity="fill_horizontal|center_vertical"
android:orientation="vertical"
android:layout_row="2"
android:layout_rowSpan="4"
android:layout_column="4">
<Button
android:text="←"
android:id="#+id/buttonBackspace"
style="#style/KeypadFunctionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="+"
android:id="#+id/buttonPlus"
style="#style/KeypadFunctionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="-"
android:id="#+id/buttonMinus"
style="#style/KeypadFunctionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="*"
android:id="#+id/buttonMultiply"
style="#style/KeypadFunctionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="/"
android:id="#+id/buttonDivide"
style="#style/KeypadFunctionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:text="7"
android:id="#+id/digit7"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_row="2"
android:layout_column="0" />
<Button
android:text="8"
android:id="#+id/digit8"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="1"
android:layout_row="2" />
<Button
android:text="9"
android:id="#+id/digit9"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="2"
android:layout_row="2" />
<Button
android:text="4"
android:id="#+id/digit4"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_row="3"
android:layout_column="0" />
<Button
android:text="5"
android:id="#+id/digit5"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="1"
android:layout_row="3" />
<Button
android:text="6"
android:id="#+id/digit6"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="2"
android:layout_row="3" />
<Button
android:text="1"
android:id="#+id/digit1"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_row="4"
android:layout_column="0" />
<Button
android:text="2"
android:id="#+id/digit2"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="1"
android:layout_row="4" />
<Button
android:text="3"
android:id="#+id/digit3"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="2"
android:layout_row="4" />
<Button
android:text=","
android:id="#+id/buttonComma"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_row="5"
android:layout_column="0" />
<Button
android:text="0"
android:id="#+id/digit0"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadButton"
android:layout_column="1"
android:layout_row="5" />
<Button
android:text="="
android:id="#+id/buttonResult"
android:layout_gravity="fill_horizontal|center_vertical"
style="#style/KeypadFunctionButton"
android:layout_column="2"
android:layout_row="5" />
</GridLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".CalcActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="1"
android:id="#+id/firstOperand"
style="#style/KeypadButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/firstOperand"
android:text="+"
android:id="#+id/operator"
style="#style/KeypadFunctionButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/operator"
android:text="1"
android:id="#+id/secondOperand"
style="#style/KeypadButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/secondOperand"
android:text="="
android:id="#+id/equalView"
style="#style/KeypadFunctionButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/equalView"
android:text="2"
android:id="#+id/resultView"
style="#style/KeypadButton" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/firstOperand"
android:id="#+id/seekBar"
android:layout_gravity="center_vertical"
android:onClick=""
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/firstOperand"
android:layout_toRightOf="#id/seekBar"
android:id="#+id/progressImage"
android:src="#drawable/ic_action_cat"
android:layout_gravity="center"
android:layout_alignParentRight="true" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/progressImage"
android:layout_alignParentRight="true"
android:text="←"
android:id="#+id/buttonBackspace"
style="#style/KeypadFunctionButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/seekBar"
android:text="7"
android:id="#+id/digit7"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/seekBar"
android:layout_toRightOf="#id/digit7"
android:text="8"
android:id="#+id/digit8"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/seekBar"
android:layout_toRightOf="#id/digit8"
android:text="9"
android:id="#+id/digit9"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/buttonBackspace"
android:text="+"
android:id="#+id/buttonPlus"
style="#style/KeypadFunctionButton"
android:layout_alignParentRight="true" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit7"
android:text="4"
android:id="#+id/digit4"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit7"
android:layout_toRightOf="#id/digit4"
android:text="5"
android:id="#+id/digit5"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit7"
android:layout_toRightOf="#id/digit5"
android:text="6"
android:id="#+id/digit6"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/buttonPlus"
android:text="-"
android:id="#+id/buttonMinus"
style="#style/KeypadFunctionButton"
android:layout_alignParentRight="true" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit4"
android:text="1"
android:id="#+id/digit1"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit4"
android:layout_toRightOf="#id/digit1"
android:text="2"
android:id="#+id/digit2"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit4"
android:layout_toRightOf="#id/digit2"
android:text="3"
android:id="#+id/digit3"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/buttonMinus"
android:text="*"
android:id="#+id/buttonMultiply"
style="#style/KeypadFunctionButton"
android:layout_alignParentRight="true" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text=","
android:id="#+id/buttonComma"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit1"
android:layout_toRightOf="#id/buttonComma"
android:text="0"
android:id="#+id/digit0"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/digit1"
android:layout_toRightOf="#id/digit0"
android:text="="
android:id="#+id/buttonResult"
style="#style/KeypadFunctionButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/buttonMultiply"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="/"
android:id="#+id/buttonDivide"
style="#style/KeypadFunctionButton" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".CalcActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/assignment">
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="50"
android:id="#+id/textView"
style="#style/KeypadButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="+"
android:id="#+id/textView2"
style="#style/KeypadFunctionButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="51"
android:id="#+id/textView3"
style="#style/KeypadButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="="
android:id="#+id/textView4"
style="#style/KeypadFunctionButton" />
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="101"
android:id="#+id/textView5"
style="#style/KeypadButton" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4">
<SeekBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/seekBar"
android:layout_weight="3" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressImage"
android:src="#drawable/ic_action_cat"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6">
<Space
android:layout_width="0dp"
android:layout_height="20px"
android:layout_weight="3"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="←"
android:id="#+id/button"
style="#style/KeypadFunctionButton" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/upperDigits">
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="7"
android:id="#+id/button2"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="8"
android:id="#+id/button3"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="9"
android:id="#+id/button4"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="+"
android:id="#+id/button5"
style="#style/KeypadFunctionButton" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/middleDigits">
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="4"
android:id="#+id/button6"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="5"
android:id="#+id/button7"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="6"
android:id="#+id/button8"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="-"
android:id="#+id/button9"
style="#style/KeypadFunctionButton" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/lowDigits">
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="1"
android:id="#+id/button10"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="2"
android:id="#+id/button11"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="3"
android:id="#+id/button12"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="*"
android:id="#+id/button13"
style="#style/KeypadFunctionButton" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/bottomDigits">
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text=","
android:id="#+id/button14"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="0"
android:id="#+id/button15"
style="#style/KeypadButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="="
android:id="#+id/button16"
style="#style/KeypadFunctionButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="/"
android:id="#+id/button17"
style="#style/KeypadFunctionButton" />
</LinearLayout>
</LinearLayout>
EDIT: both my and chiru's attempts with a relative layout ends with expanded progress bar section taking all available space.
Look like i almost did what you want using LinearLayout. Take a look of screenshot bro.
<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"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".CalcActivity" >
<LinearLayout
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/seekbar"
android:layout_alignParentBottom="true"
android:layout_marginBottom="25dp"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="9" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="8" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="7" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="6" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="5" />
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="3" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="2" />
<Button
android:id="#+id/button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="," />
<Button
android:id="#+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="0" />
<Button
android:id="#+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="=" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="←" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/assignment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:orientation="horizontal"
android:weightSum="5" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="50"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="+"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="51"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="="
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="101"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/assignment"
android:layout_below="#+id/assignment"
android:layout_marginTop="32dp"
android:orientation="horizontal" >
<SeekBar
android:id="#+id/seekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="3" />
<ImageView
android:id="#+id/progressImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
As i don't have those styles, i have been forced to remove it.
edited screenshot:

Layout different on android 2.3

My buttons on 2.3 are not showing like the suppose to.
Anyone could help me?
This is how they are shown on 2.3:
And this is on 4.4 how it should be:
This is my layout on V9:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/numkeyBoard"
>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
style="#style/test.Button.Num"
android:id="#+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="1"
android:tag="1" />
<Button
style="#style/test.Button.Num"
android:id="#+id/button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="2"
android:tag="2" />
<Button
style="#style/test.Button.Num"
android:text="3"
android:id="#+id/button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="3" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
style="#style/test.Button.Num"
android:text="4"
android:id="#+id/button_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="4" />
<Button
style="#style/test.Button.Num"
android:text="5"
android:id="#+id/button_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="5" />
<Button
style="#style/test.Button.Num"
android:text="6"
android:id="#+id/button_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="6" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
style="#style/test.Button.Num"
android:text="7"
android:id="#+id/button_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="7" />
<Button
style="#style/test.Button.Num"
android:text="8"
android:id="#+id/button_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="8" />
<Button
style="#style/test.Button.Num"
android:text="9"
android:id="#+id/button_9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="9" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
style="#style/test.Button.Num"
android:text="C"
android:id="#+id/button_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="C" />
<Button
style="#style/test.Button.Num"
android:text="0"
android:id="#+id/button_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:tag="0"
/>
<Button
style="#style/test.Button.Num"
android:text="OK"
android:id="#+id/button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:enabled="false"
android:tag="ok" />
</TableRow>
EDIT:
When I add a number second number to 1 2 3 ... until 9 then the buttons are all the same.
How can I fix this without adding a 2 digit?
Try adding android:stretchColumns="*" to the attributes defined under TableLayout

Android GridLayout of Buttons with no gaps

What is the trick for removing all gaps between an GridLayout containing buttons?
I'm using XML to define the layout. Here is what it looks like:
And here is the XML:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:alignmentMode="alignMargins"
android:clipToPadding="false"
android:columnCount="4"
android:fitsSystemWindows="false"
android:layoutMode="clipBounds"
android:orientation="horizontal"
android:padding="0dp"
android:rowCount="3"
android:adjustViewBounds="true"
android:useDefaultMargins="true" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal|fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:padding="0dp"
android:text="2" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="3" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="4" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="6" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_rowSpan="2"
android:layout_weight="1"
android:text="7" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_rowSpan="2"
android:layout_weight="1"
android:text="8" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="9" />
</GridLayout>
try this in your xml:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal|fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#ef2c6e"
android:text="1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#c2afdc"
android:padding="0dp"
android:text="2" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#d2f2f2"
android:text="3" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#c2dfa2"
android:text="4" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#1f9fcd"
android:text="5" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#f251ff"
android:text="6" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_rowSpan="2"
android:layout_weight="1"
android:background="#a2dfaf"
android:text="7" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_rowSpan="2"
android:layout_weight="1"
android:background="#daaf2f"
android:text="8" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#f21fa2"
android:text="9" />
Here's the screenshot:
Use a gridview instead of gridLayout and set the properties
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"

My android layout changes each time i chose a different device in emulator even if they have approximately same size?

Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
tools:context=".MainActivity" >
<TextView
android:id="#+id/ResultText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="20sp"
android:layout_marginTop="5dp"
android:background="#EEEEEE" />
<TextView
android:id="#+id/InputText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ResultText"
android:layout_below="#+id/ResultText"
android:background="#BBBBBB"
android:gravity="right"
android:textColor="#FFFFFF"
android:layout_marginTop="4dp"
android:textSize="15sp" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/button1"
android:text="5" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_alignTop="#+id/button6"
android:text="7" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_alignTop="#+id/button7"
android:text="8" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button5"
android:layout_below="#+id/button5"
android:text="9" />
<Button
android:id="#+id/buttonMultiply"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/buttonDivide"
android:text="x" />
<Button
android:id="#+id/buttonSubtract"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonAdd"
android:layout_alignBottom="#+id/buttonAdd"
android:layout_alignParentRight="true"
android:text="-" />
<Button
android:id="#+id/buttonDivide"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button8"
android:layout_alignBottom="#+id/button8"
android:layout_alignLeft="#+id/buttonAdd"
android:text="/" />
<Button
android:id="#+id/buttonAdd"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_toLeftOf="#+id/buttonSubtract"
android:text="+" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button8"
android:layout_toLeftOf="#+id/buttonDivide"
android:text="4" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button7"
android:layout_toLeftOf="#+id/button8"
android:text="3" />
<Button
android:id="#+id/buttonDot"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button0"
android:layout_alignBottom="#+id/button0"
android:layout_alignLeft="#+id/button7"
android:text="." />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button3"
android:layout_alignBottom="#+id/button3"
android:layout_toLeftOf="#+id/button3"
android:text="2" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button0"
android:layout_toLeftOf="#+id/button7"
android:text="6" />
<Button
android:id="#+id/button0"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button9"
android:layout_alignBottom="#+id/button9"
android:layout_alignLeft="#+id/button6"
android:text="0" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/InputText"
android:layout_marginTop="26dp"
android:layout_toLeftOf="#+id/button2"
android:text="1" />
<Button
android:id="#+id/buttonEqual"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonDot"
android:layout_alignBottom="#+id/buttonDot"
android:layout_alignRight="#+id/buttonMultiply"
android:layout_toRightOf="#+id/button8"
android:text="=" />
<Button
android:id="#+id/buttonDel"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonDot"
android:layout_toRightOf="#+id/buttonDot"
android:text="del" />
<Button
android:id="#+id/buttonSin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button9"
android:layout_below="#+id/button9"
android:text="sin" />
<Button
android:id="#+id/buttonCos"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button0"
android:layout_alignTop="#+id/buttonSin"
android:text="cos" />
<Button
android:id="#+id/buttonTan"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonDot"
android:layout_alignTop="#+id/buttonCos"
android:text="tan" />
<Button
android:id="#+id/buttonCot"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/buttonSec"
android:text="cot" />
<Button
android:id="#+id/buttonSec"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonCosec"
android:layout_alignBottom="#+id/buttonCosec"
android:layout_toLeftOf="#+id/buttonCot"
android:text="sec" />
<Button
android:id="#+id/buttonCosec"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonTan"
android:layout_alignBottom="#+id/buttonTan"
android:layout_toLeftOf="#+id/buttonSec"
android:layout_marginLeft="1dp"
android:text="csec" />
<Button
android:id="#+id/buttonPow"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonSin"
android:layout_below="#+id/buttonSin"
android:layout_alignRight="#+id/buttonSin"
android:gravity="left"
android:textSize="10sp"
android:text="yX" />
<Button
android:id="#+id/buttonLog10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonPow"
android:layout_toRightOf="#+id/buttonPow"
android:text="log" />
<Button
android:id="#+id/buttonLoge"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonLog10"
android:layout_alignBottom="#+id/buttonLog10"
android:layout_toRightOf="#+id/buttonLog10"
android:text="ln" />
<Button
android:id="#+id/buttonSquare"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonLoge"
android:layout_toRightOf="#+id/buttonLoge"
android:text="sqr" />
<Button
android:id="#+id/buttonSqrt"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonSquare"
android:layout_toRightOf="#+id/buttonSquare"
android:text="sqrt" />
<Button
android:id="#+id/buttonFactorial"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/buttonSqrt"
android:text="x!" />
<Button
android:id="#+id/buttonSinh"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonPow"
android:layout_below="#+id/buttonPow"
android:layout_toLeftOf="#+id/buttonLoge"
android:text="sinh" />
<Button
android:id="#+id/buttonCosh"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonSinh"
android:layout_alignBottom="#+id/buttonSinh"
android:layout_alignLeft="#+id/buttonLoge"
android:layout_toLeftOf="#+id/buttonSqrt"
android:text="cosh" />
<Button
android:id="#+id/buttonTanh"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonSqrt"
android:layout_alignRight="#+id/buttonFactorial"
android:layout_alignTop="#+id/buttonCosh"
android:text="tanh" />
</RelativeLayout>
here are some screen shots:
As you can see the left portion is not filled completely it is on a 4.65 inch xhdpi screen
On a 4 inch hdpi screen its perfect covering full width and full height
Basically, what Ben Pearson suggested, you can use TableLayout and several TableRow layouts. For example, a single row layout XML might look like this:
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="7" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="#+id/buttonDivide"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="/" />
<Button
android:id="#+id/buttonMultiply"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="x" />
</TableRow>
Note that since TableRow is a subclass of LinearLayout, it understands the layout_weight attribute on its children. Set the layout_width to 0dp and layout_weight to 1 on each button (or 2, for some buttons).

Categories

Resources