Is it possible to make a rubber marking in the application, so that the elements added from the code are complemented from left to right, with a transition to the next line?

layout:

button1 button2 button3 button4 button5

button6 button7 button8 button9 button10

button11 button12

  • one
    Yes you can. Use GridLayout - Android Android
  • 2
    Use FlowLayout - YuriiSPb

1 answer 1

What you need is called FlowLayout

Use one of the libraries: FlowLayout or android-flowlayout

In the case of the first one, add FlowLayout to the markup, and add the necessary number of your widgets to it, which should be transferred to another line if they do not fit

 <com.wefika.flowlayout.FlowLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="start|top"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Lorem ipsum" /> <!-- тут ещё много вьюх --> </com.wefika.flowlayout.FlowLayout> 

It turns out like this:

enter image description here


There is a container from Google's FlexboxLayout support libraries - a much more functional widget than FlowLayout

  • 3
    There is a container from Google's FlexboxLayout support FlexboxLayout - a much more functional widget than FlowLayout - pavlofff
  • @pavlofff, added this in response) - JuriySPb