Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place floating action button to right bottom of screen inside Constraint Layout?

I have a ScrollView at the top, inside that I have a ConstraintLayout. Setting height to match_parent doesn't work in ConstraintLayout so the height doesn't match the screen. Inside my ConstraintLayout I have a floating action button and it doesn't stay at the right bottom of the screen, but it stays at the right bottom of ConstraintLayout.

Image of my screen

enter image description here

How can I make the floating action button stay at the right bottom of the screen?

like image 679
hskocadag Avatar asked Mar 02 '18 12:03

hskocadag


2 Answers

If your FAB is inside constraint layout try like this

<android.support.constraint.ConstraintLayout
    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.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:clickable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@drawable/icon" />
</android.support.constraint.ConstraintLayout>
like image 105
SaravInfern Avatar answered Sep 30 '22 18:09

SaravInfern


 <android.support.design.widget.FloatingActionButton
    android:id="@+id/contactBtn"
    android:layout_width="53dp"
    android:layout_height="62dp"
    android:clickable="true"
    android:layout_gravity="bottom|right"
    app:srcCompat="@android:drawable/ic_menu_send" />

This Worked For me..

android:layout_gravity="bottom|right"
like image 41
Sandeep PS Avatar answered Sep 30 '22 18:09

Sandeep PS