Suppose I have a LinearLayout (width and height match_parent) with weightSum = "5" and then horizontally
I put 5 TableLayout ( wrap_content width and height) using layout_weight = "1" , so each TableLayout is 1/5 of its parent element.
But after that, in each TableLayout I put a TextView (width and height of wrap_content), and everything goes wrong (from my point of view):
if the text is long, then it forces its parent layout (in our case, TableLayout) to spend , and therefore 1/5 of the TableLayout from LinearLayout parent is no longer respected, although I specified TextView, s ellipsize = "end".
Well, after doing some reserch, I found that setting the layout_width is stronger than any other attribute (like weightSum) .
In my case, I set TableLayout width = wrap_content , but also layout_weight = "1" , but since it is wrap_content, it is usually consumed after its contents and does not respect weight.
Can someone give me some solutions how my table layout will respect weight? (because I donβt want my layout to be out of proportion and spent after the length of the children's text view).
Thank you for your kind image. Here is my code:
< LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:weightSum="5" > <TableLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:ellipsize="end" android:maxLines="1" android:text="test1test2test3test4test5" android:textSize="20dp"/> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> </TableLayout> </TableLayout> <TableLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="test" android:textSize="20dp" /> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> </TableLayout> </TableLayout> <TableLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="test" android:textSize="20dp" /> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> </TableLayout> </TableLayout> <TableLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="test" android:textSize="20dp" /> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> </TableLayout> </TableLayout> <TableLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="test" android:textSize="20dp" /> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> </TableLayout> </TableLayout> </LinearLayout>
source share