Layout buttons so each divides up the space equally

巧了我就是萌 提交于 2019-12-19 05:18:51

问题


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 "1" for each button would do the trick, but maybe my layout_width needs to be changed?


回答1:


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.




回答2:


I would set the layout_width of each button to 0px, then use the layout_weight=1 trick you mentioned.



来源:https://stackoverflow.com/questions/2285150/layout-buttons-so-each-divides-up-the-space-equally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!