Android: Place FloatingActionButton

1

I have a problem when placing two FloatingActionButton, I want to place the Home button next to the one of Images but it is not staying, I hope and you can help me. Thanks

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/main.collapsing"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        app:title="Bienvenido">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="30dp"
            android:lineSpacingExtra="8dp"
            android:id="@+id/data_checkin" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_picture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:src="@drawable/picture"
            android:tint="#FFF"
            app:backgroundTint="@color/colorAccent"
            app:borderWidth="0dp"
            app:fabSize="mini"
            app:layout_anchorGravity="bottom|end"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_alignTop="@+id/fabmain2"
            android:layout_toStartOf="@+id/fabmain2"
            android:layout_marginEnd="20dp" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginLeft="16dp"
            android:src="@drawable/home"
            android:tint="#FFF"
            app:backgroundTint="@color/colorAccent"
            app:borderWidth="0dp"
            app:fabSize="mini"
            app:layout_anchorGravity="bottom|end"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="23dp"
            android:layout_alignBottom="@+id/imageView8"
            android:layout_marginBottom="29dp"
            android:layout_alignParentEnd="true" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/main.toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeScot"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>
    
asked by Javier fr 13.12.2016 в 21:24
source

2 answers

1

Try this with friend:

   <RelativeLayout
            android:layout_gravity="bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_picture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:src="@drawable/picture"
            android:tint="#FFF"
            app:backgroundTint="@color/colorAccent"
            app:borderWidth="0dp"
            app:fabSize="mini"
            app:layout_anchorGravity="bottom|end"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_toLeftOf="@+id/fab_home"
            android:layout_marginEnd="20dp" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginLeft="16dp"
            android:src="@drawable/home"
            android:tint="#FFF"
            app:backgroundTint="@color/colorAccent"
            app:borderWidth="0dp"
            app:fabSize="mini"
            app:layout_anchorGravity="bottom|end"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="23dp"
            android:layout_alignBottom="@+id/imageView8"
            android:layout_marginBottom="29dp"
            android:layout_alignParentEnd="true" />

        </RelativeLayout>
    
answered by 13.12.2016 / 23:08
source
1

Keep in mind that if you want the two buttons aligned, they must have the same margins.

To align the buttons, on the left side define gravity:

android:layout_gravity="bottom|left|end"

would be:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_picture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left|end"
    android:src="@drawable/picture"
    android:tint="#FFF"
    app:backgroundTint="@color/colorAccent"
    app:borderWidth="0dp"
    app:fabSize="mini"
    app:layout_anchorGravity="bottom|end"
    android:layout_marginRight="16dp"
    android:layout_marginEnd="23dp"
    android:layout_marginBottom="29dp" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginLeft="16dp"
    android:src="@drawable/home"
    android:tint="#FFF"
    app:backgroundTint="@color/colorAccent"
    app:borderWidth="0dp"
    app:fabSize="mini"
    app:layout_anchorGravity="bottom|end"
    android:layout_marginRight="16dp"
    android:layout_marginEnd="23dp"
    android:layout_marginBottom="29dp"
    android:layout_alignParentEnd="true" />
    
answered by 13.12.2016 в 21:46