Jérôme
Jérôme

Reputation: 138

Float action button anchor with include layout

do you know if it is possible to use the id views included in a layout as anchor of a FAB ? For example :

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/map"
    app:layout_anchorGravity="bottom|right|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_menu_add" />

"@id/map" is inside the inclued layout content_main.

With this code I currently get the follow error:

Error:(30, 28) No resource found that matches the given name (at 'layout_anchor' with value '@id/map').

For information I'm use the include for trying to reduce my main layout size.

It seem that "@id/map" is not visible for the FAB anchor. But I perhaps doing something wrong.

Upvotes: 3

Views: 1836

Answers (3)

Gomez NL
Gomez NL

Reputation: 942

In some cases it's because the AppBarLayout is declared after the view calling it as anchor in the xml file.

Upvotes: 0

Deny
Deny

Reputation: 51

I think plus"+" is missing in app:layout_anchor="@+id/map"

Upvotes: 0

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75778

I guess you are missing Tag Id android:id="@+id/map"

Open your @layout/content_main

Floating action buttons are used for a special type of promoted action. They are distinguished by a circled icon floating above the UI and have special motion behaviors related to morphing, launching, and the transferring anchor point.

Error:(30, 28) No resource found that matches the given name (at 'layout_anchor' with value '@id/map').

Upvotes: 4

Related Questions