How to make a button with a weight of 3 equal in width to three buttons with a weight of 1? The red-signed layout_weight buttons.

enter image description here

<TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/buttonHistory" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" android:text="Button" /> <Button android:id="@+id/buttonBackspace" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="7" /> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="8" /> <Button android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="9" /> <Button android:id="@+id/buttonDivide" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="/" /> 
  • layout_width is equal to what? 0dp? - eugeneek
  • android: layout_width = "match_parent" - Chinko Manko
  • one
    Add full xml markup to the question. - eugeneek

2 answers 2

Try this

  <Button android:id="@+id/buttonHistory" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="0.75" android:text="Button" /> <Button android:id="@+id/buttonBackspace" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="0.25" android:text="Button" /> 

    Do not use weights in this way inside TableLayout . To stretch an element into several columns there is a special attribute android:layout_span :

     <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/buttonHistory" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_span="3" android:text="Button" /> <Button android:id="@+id/buttonBackspace" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7" /> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="8" /> <Button android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="9" /> <Button android:id="@+id/buttonDivide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="/" /> </TableRow> </TableLayout>