Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alignment issue with gridlayout

Tags:

android

I have a number pad as shown

here

As you can see, buttons with only single line are not properly aligned. I got to know that by setting android:baselineAligned as false we can solve this. But GridLayout does not have any such property.

How can i solve it?

EDIT:

<RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" >

        <GridLayout
            android:id="@+id/buttons_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alignmentMode="alignMargins"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/phone_number"
            android:layout_marginRight="@dimen/buttons_margin_right"
            android:layout_marginTop="10dp"
            android:columnCount="3" >

            <Button
                android:id="@+id/button1"
                android:layout_width=""65dp
                android:layout_height=""40dp
                android:textColor="@android:color/white"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:layout_marginLeft="10dp"
                android:text="1" />

           <Button
                android:id="@+id/button2"
                android:layout_width=""65dp
                android:layout_height=""40dp
                android:textColor="@android:color/white"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:layout_marginLeft="10dp"
                android:text="2\nABC" />

.
.
.
      </GridLayout>
<RelativeLayout>
like image 665
Rohit Walavalkar Avatar asked Feb 12 '13 11:02

Rohit Walavalkar


2 Answers

I had the same problem also with a fixed height of the textviews which were children of the appcombat GridLayout. The wrong alignment showed up everytime I had a cell with a textview with two lines and not like the others with one.

For me the rows got correctly aligned when I added an

grid:layout_rowWeight="1"

Can't explain it, but it worked.

like image 127
Logarith Avatar answered Nov 08 '22 05:11

Logarith


I managed to solve this problem by wrapping every element with a dummy layout:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/button1"
        android:layout_width="65dp"
        android:layout_height="40dp"
        android:textColor="@android:color/white"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:layout_marginLeft="10dp"
        android:text="1" />
</RelativeLayout>
like image 41
Levinthann Avatar answered Nov 08 '22 07:11

Levinthann