Mirko Marasco
Mirko Marasco

Reputation: 107

Positioning floating action button at bottom right

I implemented a floating action button inside a fragment, placing it at the bottom right with the following source code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">


 <ListView
     android:id="@+id/listtipologie"
     style="@style/Widget.AppCompat.Light.ListView.DropDown"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="1"
     android:clickable="false"
     android:divider="@null"
     android:dividerHeight="10dp"
     android:focusable="false"
     android:footerDividersEnabled="false"
     android:headerDividersEnabled="false"
     android:padding="10dip"></ListView>

  <android.support.design.widget.FloatingActionButton
     android:id="@+id/submit"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_margin="16dp"
     android:clickable="true"
     android:gravity="right"
     android:layout_alignParentBottom="true"
     android:layout_alignParentEnd="true"
     android:layout_alignParentRight="true"
     android:layout_gravity="end|bottom"
     android:layout_below="@id/listtipologie"
     app:srcCompat="@drawable/submit_icon" />



</LinearLayout>

The display on android studio is as follows:

enter image description here

But when I run it on the phone, the floating action button does not appear in the lower right but a bit higher. App is displayed in this way:

enter image description here

Can anyone help me? Thanks in advance.

Upvotes: 1

Views: 7202

Answers (1)

Satender Kumar
Satender Kumar

Reputation: 635

Use FrameLayout instead of LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">


 <ListView
     android:id="@+id/listtipologie"
     style="@style/Widget.AppCompat.Light.ListView.DropDown"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clickable="false"
     android:divider="@null"
     android:dividerHeight="10dp"
     android:focusable="false"
     android:footerDividersEnabled="false"
     android:headerDividersEnabled="false"
     android:padding="10dip"></ListView>

  <android.support.design.widget.FloatingActionButton
     android:id="@+id/submit"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_margin="16dp"
     android:clickable="true"
     android:layout_gravity="bottom|right"
     app:srcCompat="@drawable/submit_icon" />

</FrameLayout>

Upvotes: 4

Related Questions