Hello!

Tell me, please, why in Android Studio LinearLayout does not allocate for each presentation exactly 50% of its width?

Example:

alt text

Each android:layout_weight is 1 , however, in the preview area, the first button clearly takes up more space.

Eclipse works fine !!!

  • one
    try to install android:layout_width="0dp" - Barmaley
  • 2
    And weight_sum for leyauta = 1, if I do not think so. - Vladyslav Matviienko
  • @metalurgus yes, the main LinearLayout weight_sum property is equal to 1, is this not correct? - Artyomich
  • @Barmaley here [here] [1] also mentioned this, but it did not help as soon as I did not try. [1]: android-ru.info/kak-rabotaet-android-layout-weight - Artyomich
  • @metalurgus correctly noticed! The weight_sum property must be removed from the main LinearLayout. Thank! Make the answer, please, I will put a plus! - Artyomich

2 answers 2

Sum up @Barmaley & @metalurgus :

1) you do not need weight_sum .

2) in both buttons it is necessary to reset the width:

android: layout_width = "0dp"

  • Yes, thank you) Understood. - Artyomich
  • Although, if the layout_width property of the buttons is equal to wrap_content, then the width of the buttons is also distributed equally, why it is necessary to set 0dp, what is this feature, please tell me? - Artyomich
  • If both buttons set the width of the match_parent will also work - katso
  • @ Artyomich, IMHO, better still 0 set. For elements will expand either by weight or by specified specific DP. As a result, the readability of the code, for me, improves. - Yuriy SPb
  • 2
    @Artyomich> Although, if the buttons layout_width property is equal to wrap_content, then the width of the buttons is also distributed equally, why it is necessary to set 0dp, what is this feature, please tell me This is only as long as the buttons of the text of the same length. Try to put a different length, and you will see the difference. - Vladyslav Matviienko
 android:weightSum="1" 

Remove or set = "2" - and everything will be ok.