I have a number pad as shown
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>
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With