I see strange behavior of simple buttons, when their text splits on several lines. I have it in more complex situation, but even in the simplest one it happens. With this layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111" />
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111 222 333" />
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111 222 333 444 555 666" />
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111" />
</LinearLayout>
the result is:
Buttons go down and down with every next line of text. I want them in a line. Is this an android bug and how to fix it?
Try this:
<?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="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="100dip"
android:layout_height="70dip"
android:layout_gravity="center"
android:text="111" />
<Button
android:layout_width="100dip"
android:layout_height="70dip"
android:layout_gravity="center"
android:text="111 222 333" />
<Button
android:layout_width="100dip"
android:layout_height="70dip"
android:layout_gravity="center"
android:text="111 222 333 444 555 666" />
<Button
android:layout_width="100dip"
android:layout_height="70dip"
android:layout_gravity="center"
android:text="111" />
</LinearLayout>
</LinearLayout>
Set LinearLayout's android:baselineAligned
to false
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:baselineAligned="false">
do something like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/btn1"
android:layout_width="100dip"
android:layout_height="70dip"
android:text="111" />
<Button
android:layout_toRightOf="@+id/btn1"
android:id="@+id/btn2"
android:layout_width="100dip"
android:layout_height="70dip"
android:text="111 222 333" />
<Button
android:layout_toRightOf="@+id/btn2"
android:id="@+id/btn3"
android:layout_width="100dip"
android:layout_height="70dip"
android:text="111 222 333 444 555 666" />
<Button
android:layout_toRightOf="@+id/btn3"
android:id="@+id/btn4"
android:layout_width="100dip"
android:layout_height="70dip"
android:text="111" />
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With