Floating Action Button in wrong position

Cimoe :

I have Floating Action Buttons in two of my Fragment layouts and sometimes they move to the wrong position, altough I use CoordinatorLayout.

This is how it should look

This is how it somtetimes look when i open the Fragment

This is the code of my fragment:

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

<LinearLayout android:id="@+id/notes_layout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.NotesFragment">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/notes_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/new_note_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:clickable="true"
    android:src="@drawable/ic_add_black_48dp"
    app:layout_anchor="@id/notes_layout"
    app:layout_anchorGravity="bottom|center"
    android:onClick="openNewNote"/>

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

Does anyone have an idea why the FAB sometimes move to the wrong position?

Vijay :

I ran into the same issue. The problem is with the combination of app:layout_anchor and com.android.support.design:24.2.0+

I was able to fix this issue by either removing the app:layout_anchor property from the fab or by reverting to an older version of the design library. 24.1.1 worked fine for me. I also had to revert my appcompat v7 library to 24.1.1.

I hope this helps.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=454436&siteId=1