Create TextViews with equal width in a row
<p>I am trying to create a layout with three textviews beside each other. The textviews are of different length. </p>

<p>All I want to do is to arrange them so that they always have equal layout_width irrespective of the length of their text.</p>

<p>Approaches I tried:</p>

<p>1) I tried using linear_layout and setting the weight of textviews to be 1 but that does not do it since it applies only for the remaining width after all textViews are positioned.</p>

<p>2) I also tried using table layout and stretching all the columns by using stretchColumns="*". but that also allocates the required width to the length of the texts and only then does it stretch the columns.</p>

<p>3) This is a hack but this is not working either. I tried to have a linear layout inside a relative layout with three textviews to have no text but force them to be of equal widths by setting their weights. This works but then I want my next views which are in the relative layout to align themselves to the right and left edges of the views within the linear layout. But this does not work. Here is my layout that I used for this.</p>

<pre><code>        &lt;RelativeLayout
            android:layout_width="fill_parent" android:layout_height="fill_parent" &gt;
            &lt;!-- This is a hack to have all three textviews in a row to obtain equal width --&gt;
            &lt;LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" &gt;
                &lt;TextView android:id="@+id/tv_ref1"
                    android:layout_width="0dp" android:layout_height="wrap_content"
                    android:text="My"
                    android:layout_weight="1.0"
                    android:gravity="center" /&gt;
                &lt;TextView android:id="@+id/tv_ref2"
                    android:layout_width="0dp" android:layout_height="wrap_content"
                    android:text="My"
                    android:layout_weight="1.0"
                    android:gravity="center" /&gt;
                &lt;TextView android:id="@+id/tv_ref3"
                    android:layout_width="0dp" android:layout_height="wrap_content"
                    android:text="My ghghhfghjjghjkkhgfhfghfjhjh"
                    android:layout_weight="1.0"
                    android:gravity="center" /&gt;
            &lt;/LinearLayout&gt;


            &lt;TextView
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_below="@id/tv_ref1"
                android:gravity="center"
                android:text="Text Text Text"
                android:textColor="@color/white" /&gt;
            &lt;TextView
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_below="@id/tv_ref1"
                android:gravity="center_horizontal"
                android:text="Med"
                android:textColor="@color/white" /&gt;
            &lt;TextView
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_below="@id/tv_ref1"
                android:gravity="center"
                android:text="Long Text wtwy yu hjsyi"
                android:textColor="@color/white" /&gt;

        &lt;/RelativeLayout&gt;
</code></pre>

<p>Please let me know what I might be doing wrong or how I can force my textviews in a row to have equal widths.</p>

<p>Thank you.</p>
