Layout buttons so each divides up the space equally

后端 未结 2 767
遇见更好的自我
遇见更好的自我 2021-01-11 14:40

Im using a LinearLayout to put two buttons horizontally side-by-side, but I want to each button to size itself to use 50% of the horizontal space. I thought layout_weight of

2条回答
  •  北海茫月
    2021-01-11 14:54

    The layout_weight attribute controls how much of the left over space each of your buttons is given. If your buttons take up different amounts of space to start with, then each of them will first be given the space they ask for, and then any remaining space will be divided up between them, meaning that you won't have an exact 50/50 split.

    You can get around this behaviour by first setting layout_width="0px" (keeping your layout_weights as they are), and relying on 50% being enough space to display each button.

提交回复
热议问题