2-column TableLayout with 50% exactly for each column

前端 未结 4 1451
醉梦人生
醉梦人生 2020-12-13 07:00

This one puzzles me since my first steps with Android. I can\'t make both columns in a 2-column TableLayout exact 50% each.

Here\'s an example:



        
4条回答
  •  Happy的楠姐
    2020-12-13 07:35

    Have you tried to set the android:layout_width attribute to 0dp (and of course keep the android:layout_weight as 1) on the child views?

    I have been in similar scenarios when I also wanted to distribute the given space equally between two child views but failed to do so since the child with "wider content" also became wider, within its parent, than its sibling. This was due to the fact that the wider child had a greater initial width. Making sure both children started of from the same width (android:layout_width="0dp" on both of them) also guaranteed to distribute the space evenly among them.

提交回复
热议问题