layout_weight属性是LinearLayout子view的专有属性, 用来说明 当LinearLayout 按照各子view的要求 分配给各子view大小 之后,如果还有剩余的空间,如何将剩余空间分配给子view。就是子view如何瓜分LinearLayout的剩余空间。
Google的文档推荐如果使用了这个属性,那么子view的layout_width(或者layout_height,这个取决于LinearLayout的orientation)应该写为0dp,原因是为了提高效率
In order to improve the layout efficiency when you specify the weight, you should change the width of the EditText
to be zero (0dp). Setting the width to zero improves layout performance because using "wrap_content"
as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.
我想说的重点是layout_weight说明的是“剩余空间”而对子view要求的空间(即layout_width的属性)无效,如果我们想等分LinearLayout的空间(不是剩余空间)那么各子view要求的空间也应该是一样的, 不然在分配剩余空间之前, 就已经不等分了。