I need to arrange a lot of buttons in a row (horizontally). For all buttons, the width is set as wrap_content . I have them in LinearLayout (horizontal). The problem is that if the total width of all buttons exceeds the width of the device screen, the buttons are not automatically transferred to the next line, but flattened into a thin strip at the end of the screen.

Question: how to make autotransfer of buttons?

Reported as a duplicate by YurySPb. android Nov 14 '17 at 6:52 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    Set the total weight of android:weightSum="100" in LinearLayout and for each button specify how many percent it can occupy on the screen using the parameter android:layout_weight="20" . For the second row, you will have to create another LinearLayout machine will not transfer. For these purposes, you need to use RelativeLayout it sets the relative position from any element. Look towards RelativeLayout it is more convenient and more dynamic than LinearLayout .

      Put all the buttons in <TabLayout></TabLayout> or in <TableRow></TableRow> .