简体   繁体   中英

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:

在此处输入图片说明

Snackbar disappeared

在此处输入图片说明

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM