Search code examples
androidandroid-studiocrashfloating-action-button

FAB layout_anchor crash with a exist resource


Today, I was making a Login Activity which used a FAB as the Login Button. The codes were right. When I was arranging the layout file, I used these codes:

android:id="@+id/floatingActionButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:clickable="true"
app:elevation="15dp"
app:layout_anchor="@id/EText1"
app:layout_anchorGravity="end"
app:fabSize="normal"
app:srcCompat="@drawable/ic_arrow_forward"

Android Studio didn't report any bugs when I typed these codes. But when I was going to run it as a debug app on my phone, it crashed with this mistake:

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

And I noticed a mistake in Render Errors:

Couldn't resolve resource @id/visible

I hope someone can help me to solve this problem. I will appreciate it if someone can give me a solution. Thanks Anyway!


Solution

  • Make sure you have a view with "EText1" id and make sure EText1 is above your FAB in your xml file. It is better to put the whole xml file.