Popescu M
Popescu M

Reputation: 72

Android Linear Layout buttons not aligning after adding text to one of them

I am trying to put 6 buttons in the middle of the screen and it worked until I added text to one of them, as you can see in the picture below :

https://i.sstatic.net/1YSo0.jpg

This is the code for the 2 buttons that causes problems :

 <LinearLayout
    android:id="@+id/tableRow3"
    android:padding="5dp"
    android:layout_gravity="center_horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/utilitiesButton"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/menu_sms"
        android:gravity="bottom|right"
        android:padding="10dp"
        android:text="0"
        android:textColor="@color/red"
        android:textSize="40dp" />

    <Button
        android:id="@+id/statisticsButton"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/menu_statistics"
        android:gravity="center_vertical|center_horizontal" />

</LinearLayout>

I need the text to be bottom|right. The bigger the text size from the left button is, right button goes down more. Any ideas on this ?

Thank you, Marius

Upvotes: 0

Views: 1045

Answers (2)

clin
clin

Reputation: 51

If you set android:baselineAligned="false" on the LinearLayout, then the buttons inside the LinearLayout would align properly.

Reference: https://possiblemobile.com/2013/10/shifty-baseline-alignment/

Upvotes: 5

Sbonelo
Sbonelo

Reputation: 684

Comment

Instead of using a LinearLayout try and use relative layout instead, with an android:gavity of fill_horizontal, and add a bit of space between your textviews, also try and decrease the padding on the first button.

Upvotes: 0

Related Questions