The long text on the button places the rows of the GridLayout

I have a GridLayout that is used to place several buttons arranged in two columns. All buttons have a fixed height and width. If one of the buttons contains too much text, the layout is messed up. I would like the layout to support the lines correctly, regardless of whether they have too much text or not (I will handle the case of displaying too much text later, using the automatic text size).

This is my code:

<GridLayout
        android:id="@+id/cont_middle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="3dp"
        android:layout_marginRight="3dp"
        android:layout_marginTop="2dp"
        android:columnCount="2"
        >

        <Button android:layout_width="120dp" android:layout_height="60dp" android:text="test"/>
        <Button android:layout_width="120dp" android:layout_height="60dp" android:text="test"/>
        <Button android:layout_width="120dp" android:layout_height="60dp" android:text="this is a really long text"/>
        <Button android:layout_width="120dp" android:layout_height="60dp" android:text="test"/>
        <Button android:layout_width="120dp" android:layout_height="60dp" android:text="test"/>
        <Button android:layout_width="120dp" android:layout_height="60dp" android:text="test"/>
</GridLayout>

Here's what it looks like:

enter image description here

This is how the layout looks (despite the text)

enter image description here

Note. I don’t want to force one line, I would like the text to turn around if it wants, the button will not change its height, but I do not want it to move.

What am I missing?

Thank.

+2
2

. , , . , .

+4

, , ,

android:maxHeight="60dp"
+1

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


All Articles