JosephG JosephG - 2 months ago 14
Android Question

Can't set my fab icon to bottom right of my page

I'm having trouble inserting the fab icon on the bottom right of my app even I set the anchor to

bottom|right
can you guys please help me doing this because the fab icon appears on the top left portion of the app.

<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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.kun.carkila.OwnerTabs">

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/plus"
app:layout_anchor="@+id/container"
app:layout_anchorGravity="bottom|right" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_directions_car_white_48dp"
app:layout_anchor="@+id/container"
app:layout_anchorGravity="bottom|right" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="#990000"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="#990000">

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

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



<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</LinearLayout>



Answer

This should work! use

android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"

.

<android.support.design.widget.FloatingActionButton
                android:layout_alignParent="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:id="@+id/fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_margin="@dimen/fab_margin"
                app:srcCompat="@drawable/ic_directions_car_white_48dp"
                app:layout_anchorGravity="bottom|right" />

woah where's ur relative layout gone which was parent of this floating button?