user1137313
user1137313

Reputation: 2410

Android Button with longer text layout

I want to have 2 buttons, equal size, with icons on them on the bottom of my Activity layout. I drew them and everything, but now that I added the icons, one button which has longer text and needs to be written on two lines, insists on being shown 3-5 pixels lower than the other one. Here is my code:

    <LinearLayout
                android:id="@+id/Buttonz"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:baselineAligned="true"
                android:paddingTop="30dp" >
            <Button
                android:id="@+id/btn_confirm"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.50"
                android:drawableLeft="@drawable/save36"
                android:text="@string/btn_lbl_confirm" />

            <Button
                android:id="@+id/btn_cancel"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.50"
                android:drawableLeft="@drawable/back36"
                android:text="@string/btn_lbl_cancel" />

</LinearLayout>

And this is the result (image)

this is how it looks after adding images to drawableLeft

As you can see, the buttons are not aligned ...

What am I doing wrong?

Upvotes: 1

Views: 1582

Answers (2)

Harshid Vasoya
Harshid Vasoya

Reputation: 5721

<LinearLayout
            android:id="@+id/Buttonz"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:paddingTop="30dp" >

        <Button
            android:id="@+id/btn_confirm"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="0.50"
            android:text="hello test \nuser how are you" />

        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="0.50"
            android:text="test user" />
    </LinearLayout>

work like charm.

Upvotes: 1

Gina
Gina

Reputation: 912

I changed the baselineAligned then two buttons matched

<LinearLayout
android:id="@+id/Buttonz"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:paddingTop="30dp" >

Upvotes: 2

Related Questions