Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button changes position when text in two lines

Tags:

android

layout

Hi I have this simple Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<Button
    android:id="@+id/btn_trigger_left"
    style="@style/triggerButton"
    android:layout_marginRight="5dip"
    android:text="Mold" />

<Button
    android:id="@+id/btn_trigger_right"
    style="@style/triggerButton"
    android:text="Fums" />

</LinearLayout>

and style is here.

<style name="triggerButton">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">50dip</item>
    <item name="android:textSize">12sp</item>
    <item name="android:gravity">center</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:layout_weight">2</item>
    <item name="android:background">@drawable/symptom_bg</item>
    <item name="android:layout_marginBottom">0dip</item>
</style>

and out put is like this. enter image description here

it is ok, but when My text is long enough to two lines button comes down like this.

enter image description here

please help me when I am doing wrong ? Thanks!

like image 999
Jignesh Ansodariya Avatar asked Mar 19 '13 08:03

Jignesh Ansodariya


2 Answers

Put

android:baselineAligned="false"

in your LinearLayout.

LinearLayout aligns the baselines of all its child controls by default and here you need to disable the behaviour.

like image 123
Anukool Avatar answered Oct 06 '22 00:10

Anukool


 <item name="android:gravity">center</item>

to

<item name="android:gravity">top</item> 

Set gravity in your style.xml as this. Hope this will help.

like image 40
Triode Avatar answered Oct 06 '22 00:10

Triode