0
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.now.sexyfacechanger.Activity_PhotoOrGallery">

    <include layout="@layout/content_activity__photo_or_gallery" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="horizontal">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_camera"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_weight="1"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_gallery"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_weight="1"/>

    </LinearLayout>


</android.support.design.widget.CoordinatorLayout>

Here is the view in android studio design, the linear layout displayed does match the parent:

enter image description here

But the output:

enter image description here

The linear layout doesn't match parent or I suspect the layout_weight applied to the two floating buttons doesn't work in Coordinator layout.

Alex
  • 881
  • 2
  • 10
  • 24
  • Have you tried `android:layout_gravity="bottom|center_horizontal"` – Selçuk Cihan Mar 26 '16 at 11:39
  • @SelçukCihan just tried, doesn't work :/ – Alex Mar 26 '16 at 11:46
  • Can you also change `android:layout_width="match_parent"` to `android:layout_width="wrap_content"` in the linear layout? – Selçuk Cihan Mar 26 '16 at 11:54
  • @SelçukCihan thanks, now the two fabs are at bottom and center horizontal. But my desired view is to split the view in to half and each fab center horizontal in each half. Would like to know the cause and the solution of this problem. – Alex Mar 26 '16 at 12:00
  • 1
    Please check this answer http://stackoverflow.com/questions/3470420/is-it-possible-to-evenly-distribute-buttons-across-the-width-of-an-android-linea – Selçuk Cihan Mar 26 '16 at 12:05

2 Answers2

5

It is because FloatingActionButton can only have a fixed size.

You can add some space between them.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal">
    <Space    
        android:layout_weight="1"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"/>
    <Space    
        android:layout_weight="2"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_gallery"/>
    <Space    
        android:layout_weight="1"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
</LinearLayout>
Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125
tiny sunlight
  • 6,231
  • 3
  • 21
  • 42
0

So, maybe if you will use LinearLayout it can help you.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="@dimen/space_small_xs"
android:weightSum="2">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="start"
    android:orientation="horizontal"
    android:paddingStart="@dimen/space_small_l"
    android:paddingEnd="@dimen/space_small_l">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button_prev"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_white_left"
        android:tint="@android:color/white"
        app:backgroundTint="@color/text_subscribe_light"
        app:fabSize="mini" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="end"
    android:orientation="horizontal"
    android:paddingStart="@dimen/space_small_l"
    android:paddingEnd="@dimen/space_small_l">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_white_right"
        android:tint="@android:color/white"
        app:backgroundTint="@color/text_subscribe_light"
        app:fabSize="mini" />
</LinearLayout>

It will look like this:

enter image description here

AlexS
  • 918
  • 1
  • 12
  • 28