Linear layout - difference between weight and FILL_PARENT

According to the document, FILL_PARENT basically allows you to view all the extra space. Weight also determines how much extra space can be used for viewing. What is the difference?

For example: What happens when I use

new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f) 
+4
source share
1 answer

FILL_PARENT allows FILL_PARENT to do all the free space. Weight makes you take a relative amount. Example: let's say you have two boxes, A and B, added to the horizontal LinearLayout in this order. If A is set to WRAP_CONTENT and B is set to FILL_PARENT , your layout

[A] [B +++++ +++++]

If you instead have a weight set to 2 and a weight B set to 2, you get

[++, A ++] [++ B ++]

If you have set weight 2 and weight B set to 4, you get

[+ A +] [+++ +++ B]

and etc.

+13
source

Source: https://habr.com/ru/post/1316715/


All Articles