0

I've encountered some strange behaviour.

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent">

            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Hi"/>

            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Hi&#10;Hello"/>

        </LinearLayout>

this code adds top margin to button that has two lines of text in it or something else that pushes it down.

enter image description here

The only workaround I've found to make it look as expected

enter image description here

is to add negative top margin and smaller padding to the button with two lines of text

            <Button
                android:layout_marginTop="-8dp"
                android:padding="2dp"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Hi&#10;Hello"/>

What causes that strange behaviour and how to handle it properly?

AlexKost
  • 2,792
  • 4
  • 22
  • 42

0 Answers0