Home » Android » xml – Adding two Button views in same cell in GridLayout in Android?-Exceptionshub

xml – Adding two Button views in same cell in GridLayout in Android?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I’m building small app calculator in Android. Attached is my super complex design. I don’t know how to fit two button views in same single cell, so each view can occupies half of cell’s space?

Here is xml:

<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:columnCount="4"
    android:rowCount="6">

<Button
        android:layout_row="1"
        android:layout_column="0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/c">
    </Button>

    <Button
        android:layout_row="1"
        android:layout_column="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="@string/left_parenthesis">
    </Button>
    <Button
        android:layout_row="1"
        android:layout_column="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/right_parenthesis">
    </Button>

Right now, left parenthesis is just overlaping right parenthesis. enter image description here

How to&Answers: