Fab in Coordinator layout with bottom padding

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Fab in Coordinator layout with bottom padding



Fab is in coordinator layout, coordinator layout has bottom padding.
There is incorrect fab behavior when snackbar showing:



Snackbar appeared:



enter image description here



Snackbar disappeared



enter image description here



This is my layout:


<?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:paddingBottom="56dp"
>

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

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:navigationIcon="@drawable/ic_categories_white_24dp"
/>

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

<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.example.FabAwareScrollingViewBehavior"
tools:listItem="@layout/list_item_view"
/>

<TextView
android:id="@+id/actions_list_empty_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="@style/TextAppearance.AppTheme.Subhead"
android:text="@string/list_empty_result"
android:textColor="?android:attr/textColorHint"
android:visibility="gone"
tools:visibility="visible"
/>

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
tools:visibility="visible"
/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_filter_white_24dp"
/>

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



What can I do to avoid this incorrect fab behavior when snackbar disappeared? Fab must place in bottom right corner, but it is located slightly below the parent container.




1 Answer
1



add this to your fab


app:layout_anchor="@id/list"
app:layout_anchorGravity="bottom|right|end"



snackbar



rootLayout, on your case use your coordinator layout id


Snackbar.make(rootLayout, "Hello Snackbar!", Snackbar.LENGTH_SHORT).show()





Thanks! But after run this I got the exception: java.lang.RuntimeException: This graph contains cyclic dependencies
– Alexey Nikitin
Aug 8 at 6:19






post your BottomNavigationView, or double check your usage of layout_anchor
– renzvader
Aug 8 at 6:48






I think bottomnavigationview does not affect on fab, because bottomnavigationview placed in main activity, and my screen is an activity view child. Seems that coordinator layout with behaviors act to fab when snackbar showing, and coordinator layout bottom padding has great importance
– Alexey Nikitin
Aug 8 at 6:55






You guys missed "+" in app:layout_anchor="@id/list". Try with this: app:layout_anchor="@+id/list" if it didn't solve the issue, remove the line and this one: android:paddingBottom="56dp"
– ʍѳђઽ૯ท
Aug 10 at 10:34



"+"


app:layout_anchor="@id/list"


app:layout_anchor="@+id/list"


android:paddingBottom="56dp"





"+" is unnecessary here. And layout_anchor does not work, if there is layout_behavior. I can not remove bottom padding
– Alexey Nikitin
Aug 10 at 17:28


"+"


layout_anchor


layout_behavior






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard