0

I am trying to create a Windows Like Calculator using Android. I choose Grid Layout for this purpose.

<?xml version="1.0"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_gravity="center"
    android:columnCount="5"
    android:orientation="horizontal"
    android:rowCount="7">

    <!-- The Text View-->


    <TextView
        android:id="@+id/textView"
        android:layout_columnSpan="5"
        android:layout_rowSpan="1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="0" />

    <!-- First Row-->


    <Button
        android:id="@+id/MC"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_columnWeight="1"
        android:layout_row="1"
        android:text="@string/MC" />

    <Button
        android:id="@+id/MR"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnWeight="1"
        android:layout_row="1"
        android:text="@string/MR" />

    <Button
        android:id="@+id/MS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_columnWeight="1"
        android:layout_row="1"
        android:text="@string/MS" />

    <Button
        android:id="@+id/MPLUS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_columnWeight="1"
        android:layout_row="1"
        android:text="@string/MPLUS" />

    <Button
        android:id="@+id/MMIN"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="4"
        android:layout_columnWeight="1"
        android:layout_row="1"
        android:text="@string/MMIN" />

    <!-- Second Row-->


    <Button
        android:id="@+id/DEL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_columnWeight="1"
        android:layout_row="2"
        android:text="@string/DEL" />

    <Button
        android:id="@+id/CE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnWeight="1"
        android:layout_row="2"
        android:text="@string/CE" />

    <Button
        android:id="@+id/C"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_columnWeight="1"
        android:layout_row="2"
        android:text="@string/C" />

    <Button
        android:id="@+id/PLUSMIN"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_columnWeight="1"
        android:layout_row="2"
        android:text="@string/PLUSMIN" />

    <Button
        android:id="@+id/RA"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="4"
        android:layout_columnWeight="1"
        android:layout_row="2"
        android:text="@string/RAC" />

    <!-- Third Row-->


    <Button
        android:id="@+id/SEVEN"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnWeight="1"
        android:layout_row="3"
        android:text="@string/SEVEN" />

    <Button
        android:id="@+id/EIGHT"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_columnWeight="1"
        android:layout_row="3"
        android:text="@string/EIGHT" />

    <Button
        android:id="@+id/NINE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_columnWeight="1"
        android:layout_row="3"
        android:text="@string/NINE" />

    <Button
        android:id="@+id/SLASH"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_columnWeight="1"
        android:layout_row="3"
        android:text="@string/SLASH" />

    <Button
        android:id="@+id/PERCENT"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="4"
        android:layout_columnWeight="1"
        android:layout_row="3"
        android:text="@string/PERCENT" />

    <!-- Fourth Row-->


    <Button
        android:id="@+id/FOUR"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnWeight="1"
        android:layout_row="4"
        android:text="@string/FOUR" />

    <Button
        android:id="@+id/FIVE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_columnWeight="1"
        android:layout_row="4"
        android:text="@string/FIVE" />

    <Button
        android:id="@+id/SIX"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_columnWeight="1"
        android:layout_row="4"
        android:text="@string/SIX" />

    <Button
        android:id="@+id/STAR"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_columnWeight="1"
        android:layout_row="4"
        android:text="@string/STAR" />

    <Button
        android:id="@+id/REVERSE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="4"
        android:layout_columnWeight="1"
        android:layout_row="4"
        android:text="@string/REVERSE" />

    <!-- FIFTH Row-->


    <Button
        android:id="@+id/ONE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnWeight="1"
        android:layout_row="5"
        android:text="@string/ONE" />

    <Button
        android:id="@+id/TWO"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_columnWeight="1"
        android:layout_row="5"
        android:text="@string/TWO" />

    <Button
        android:id="@+id/THREE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_columnWeight="1"
        android:layout_row="5"
        android:text="@string/THREE" />

    <Button
        android:id="@+id/MINUS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_columnWeight="1"
        android:layout_row="5"
        android:text="@string/MINUS" />

    <Button
        android:id="@+id/EQUAL"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_column="4"
        android:layout_gravity="start|fill_vertical"
        android:layout_row="5"
        android:layout_rowSpan="2"
        android:gravity="center"
        android:text="@string/EQUAL" />

    <!-- SIXTH Row-->


    <Button
        android:id="@+id/ZERO"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnSpan="2"
        android:layout_columnWeight="1"
        android:layout_gravity="fill_horizontal"
        android:layout_row="6"
        android:text="@string/ZERO" />

    <Button
        android:id="@+id/DOT"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_columnWeight="1"
        android:layout_row="6"
        android:text="@string/DOT" />

    <Button
        android:id="@+id/PLUS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="3"
        android:layout_columnWeight="1"
        android:layout_row="6"
        android:text="@string/PLUS" />

</GridLayout>

The previews have been uploaded to these links https://i.stack.imgur.com/9UCHz.png https://i.stack.imgur.com/krjS7.png

II want that the widgets fills all the screen on any device.

Could you help me.

Thanks in advance

Jens
  • 6,243
  • 1
  • 49
  • 79
Ben Roid
  • 9
  • 2
  • Refer to [this](http://stackoverflow.com/a/10033481/332248) answer. – Jens Apr 15 '15 at 16:10
  • possible duplicate of [GridLayout (not GridView) how to stretch all children evenly](http://stackoverflow.com/questions/10016343/gridlayout-not-gridview-how-to-stretch-all-children-evenly) – nana Apr 15 '15 at 16:13

0 Answers0