stealthjong
stealthjong

Reputation: 11093

Android Buttons pushed down when text does not fit

I have 5 buttons in the bottom of the screen (grouped in a linearlayout, with a weight of 1 each. In the screenshot, the row above b1-b5). However, when the text is more than one row, that particular button is pushed down, even outside its parent. The height of each button is a set value, equal for all buttons. The next > button is the only button in the correct position. Below some XML, but that seems all normal to me:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/h"
    android:orientation="horizontal" >

    <Button                                    }
        android:layout_width="0dp"             }
        android:layout_height="@dimen/h"       }   x5
        android:layout_weight="1"/>            }
</LinearLayout>

The LinearLayout from the buttons b1-b5 has an margin_top of 10dp.

The screenshot:

screenshot

Red line is where the buttons should align. Blue line are buttons with two lines of text, green with 3.

According to the screenshot, the buttons are pushed slightly more down the more lines of text they contain. How can I stop the buttons from being pushed down if they contain too much text? I can't use a relativelayout and have them alignTop, because I need them weighted equally

EDIT: complete (although shortened) XML

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="6dp"
    android:paddingRight="6dp"
    android:paddingTop="6dp">
    <LinearLayout
        android:id="@+id/panel1"
        android:layout_width="match_parent"
        android:layout_height="@dimen/h"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="@dimen/margin"
        android:layout_centerHorizontal="true">
        <Button 
            android:layout_width="0dp"      }
            android:layout_height="@dimen/h"    }x5
            android:layout_weight="1"/>     }
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@+id/text"
        android:layout_alignParentTop="true">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:background="@color/black"
            android:textColor="@color/white"
            android:text="@string/longtext">
        </TextView>
    </ScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/panel1"
        android:gravity="bottom">

        <LinearLayout
            android:id="@+id/panel2"
            android:layout_width="match_parent"
            android:layout_height="@dimen/h"
            android:orientation="horizontal">

            <Button
                android:layout_width="0dp"              }
                android:layout_height="@dimen/h"    }x5
                android:layout_weight="1"/>             }
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

Upvotes: 0

Views: 638

Answers (1)

MC Emperor
MC Emperor

Reputation: 22997

in the XML, set this value: android:baselineAligned="false". Strangly this does the opposite of what you expect it to do.

Upvotes: 3

Related Questions