The button changes position when the text is in two lines

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 the 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 - like this. enter image description here

this is normal, but when my text is long enough, up to two lines, the button goes down like this.

enter image description here

Please help me when I am wrong? Thanks!

+7
source share
3 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 behavior.

+8
source
  <item name="android:gravity">center</item> 

to

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

Set gravity in style.xml like this. Hope this helps.

+3
source

Correct the maximum text length in the button

 android:maxLength="20" 

Hope this helps.

0
source

All Articles