Hello! There was a need to fill the gridlayout'a with numbers to fully utilize the place (increase the buttons) and there was no free space. Is it possible to do this in some way, using gridlayout? Ie, I want to create numbers like a calculator. The android attribute: useDefaultMargins = "true" just sprawled the numbers a little. I hope clearly explained :)

Here is the code for the selected item:

<GridLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:alignmentMode="alignBounds" android:columnCount="3" android:rowCount="4" android:useDefaultMargins="true"> <Button android:text="1"/> <Button android:text="2"/> <Button android:text="3"/> <Button android:text="4"/> <Button android:text="5"/> <Button android:text="6"/> <Button android:text="7"/> <Button android:text="8"/> <Button android:text="9"/> <Button android:layout_gravity="fill_horizontal" android:layout_columnSpan="2" android:text="0" /> <Button android:text="x"/> </GridLayout> 

problem gridlayout

    1 answer 1

    screenshot

    GridLayout has a grid and a row of weights that can be used.

     <android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:grid="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" grid:alignmentMode="alignBounds" grid:columnCount="4"> <Button android:layout_width="0dp" style="?buttonStyle" android:layout_height="0dp" android:text="-1" grid:layout_columnWeight="1" grid:layout_rowWeight="1" grid:layout_gravity="fill"/> 
    • Here is stackoverflow in Russian . - eugeneek
    • I need to stretch exactly those elements that are listed above. Neither more nor less - Vasily Terkin
    • is my code not working? - Andriy Martsinkevych
    • I have already seen this answer in English stackoverflow. Not only that, he earns only when to connect to. dependencies: compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:gridlayout-v7:25.3.1', which you didn’t specify, but even so it doesn’t suit me. And I did not say that it does not work - it does not suit me. - Vasily Terkin
    • even afraid to ask why it does not suit you - Andriy Martsinkevych