I am trying to create a layout with three text fields next to each other. Textures have different lengths.
All I want to do is arrange them so that they always have equal layout width regardless of the length of the text.
The approaches I tried:
1) I tried using linear_layout and set the weight of the text views to 1, but this does not, because it only applies to the remaining width after placing all the text elements.
2) I also tried using the table layout and stretching all the columns using stretchColumns = "*". but also selects the required width in the length of the texts and only then stretches the columns.
3) It’s a hack, but it doesn’t work either. I tried to have a linear layout inside a relative layout with three text images so as not to have text, but made them have equal width by setting their weights. This works, but then I want my next views to be in relative layout to align myself to the right and left edges of the views in a linear layout. But that does not work. Here is my layout that I used for this.
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<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" />
<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" />
<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" />
</LinearLayout>
<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" />
<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" />
<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" />
</RelativeLayout>
Please let me know what I can do wrong, or how I can make my text images in a line have equal width.
Thank.
source
share