LinearLayout: layout_gravity="bottom" not working on Horizontal LinearLayout

Viewed 64238

Ok, First of all, I searched all the internet, but nobody has a similar problem like this. So, all I want is to have 3 textViews, bottom aligned with the screen and with the same width. Here is an image representing what I want:

enter image description here

And here is my code:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">
 <LinearLayout 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true">

      <TextView 
           android:text="@string/help_1"
           android:layout_weight="0.33"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@drawable/mynicebg1"

           android:layout_gravity="bottom"/>

      <TextView 
           android:text="@string/help_2"
           android:layout_weight="0.33"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@drawable/mynicebg2"

           android:layout_gravity="bottom"/>

      <TextView 
           android:text="@string/help_3"
           android:layout_weight="0.33"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@drawable/mynicebg3"

           android:layout_gravity="bottom"/>

 </LinearLayout>
 </RelativeLayout>

Well, it works when the 3 textViews have the same height, but when their size differ, I get the following result:

problem

Another strange behavior, is that when I set the layout_gravity of the biggest text to "center-vertical", I get the following result:

first workaround

So obviously, I went crazy and tried another combinations with center-vertical, but nothing worked as I wanted initially:

desperation workaround

So, any tips on how to solve this?

7 Answers

A much easier solution would be to use the < Space > tag:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <Space
           android:layout_width="0dp"
           android:layout_height="1dp"
           android:layout_weight="1" />

      <TextView 
           android:text="Any Text"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#eeffee"/>

      <TextView 
           android:text="Any Text2"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#eeeeff"/>


      <TextView 
           android:text="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#ffeeee"/>

 </LinearLayout>
Related