All good! Guys, I need your help. How to put four FloatingActionButton in a row? Any help would be useful! To make it happen
To make it happen

  • 2
    Need just like that not exactly? - Yuriy SPb

2 answers 2

You need a container, which elements in itself will arrange one after the other with the same width for each. LinearLayout will help LinearLayout , with orientation="horizontal" and internal containers with a weight of 1. In the containers, place the FAB already

 <LinearLayout android:width="match_parent" android:hight="wrap_content" android:orientation="horizontal"> <FrameLayout android:width="0dip" android:hight="wrap_content" android:weight="1"> <!-- сюда fab вставляйте --> </FrameLayout> <FrameLayout android:width="0dip" android:hight="wrap_content" android:weight="1"> <!-- сюда fab вставляйте --> </FrameLayout> <FrameLayout android:width="0dip" android:hight="wrap_content" android:weight="1"> <!-- сюда fab вставляйте --> </FrameLayout> <FrameLayout android:width="0dip" android:hight="wrap_content" android:weight="1"> <!-- сюда fab вставляйте --> </FrameLayout> </LinearLayout> 
  • brilliant! God bless you! - iFr0z
  • @ iFr0z, please) - Yuriy SPb

the use of multiple nested layouts is not entirely optimal and can inhibit the system http://developer.android.com/intl/ru/training/improving-layouts/optimizing-layout.html

It is much more practical to use RelativeLayout And "add" three more FABs to the left of the "base" (located in the lower right corner) Use android: layout_toLeftOf to place the FAB to the left of the "base", well, and the margin, of course, so that the FABs don't touch)

Markup (rough sketch, did not check in the studio):

  <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> .............................................. <android.support.design.widget.FloatingActionButton android:id="@+id/fab1" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_anchorGravity="bottom|right|end"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab2" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_anchorGravity="bottom|right|end" android:layout_toLeftOf="@+id/fab1"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab3" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_anchorGravity="bottom|right|end" android:layout_toLeftOf="@+id/fab2"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab4" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_anchorGravity="bottom|right|end" android:layout_toLeftOf="@+id/fab3"/> </RelativeLayout> 

As a result, we get only one layout

  • The solution is good, but it is relatively basic button. Those. If you use it on a larger screen, it will be somewhere in the beginning and will not reach the center. - iFr0z
  • What is the difference what screen? Everything depends on the location of the "basic button" in the example above. It is placed in the lower right corner, and where is the screen size? The next line does just that: app: layout_anchorGravity = "bottom | right | end" The rest is placed to the left of it. It's time to switch to RelativeLayout! A bunch of layouts is not cool - Roman Novoselov
  • If you need to stretch these four buttons to full screen, then yes, you cannot do without LinearLayout, but the FAB parameter is also weitht, at least you can get rid of FrameLayouts And yes, this solution does not fit the MaterialDesign concept :) - Roman Novoselov
  • I, frankly, wanted to spit on the concept of the material) it is not fully thought out) and Google admit it :) - iFr0z
  • unfounded) Well, it does not matter, the solution is found - Roman Novoselov