How does android:layout_weight work?

前端 未结 8 2047
后悔当初
后悔当初 2020-12-02 20:35

When I have the following, it shows top layout with four colors has much smaller area than the bottom layout area.

According to this documentation, when you add more

相关标签:
8条回答
  • 2020-12-02 21:08

    Building on what Janusz said, if you use fill_parent, you can then set android:layout_weight to "split" the "full area" between multiple layout items.

    The layout_weight doesn't increase the area, it increases it "right" to the area. but it's also relative to the parent. If you have a parent with a layout_height=fill_parent, with a layout_weight=0 and the parent has a sibling with the same, setting layout_weight=1 to one of the children does not affect the parent.

    Both the parent, and the sibling, would take up 50% of the available area that they can fill.

    0 讨论(0)
  • 2020-12-02 21:12

    In linear layout properties change the layout width to "fill_parent" instead of "wrap_content" hope it helps.

    0 讨论(0)
提交回复
热议问题