Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown fragments - Map Android Studio

I'm doing an accessibility project and need to use the API Map. I can not see the map in Android Studio. This error appears:

Unknown Fragments - The <fragment> tag allows the layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout.
- <fragment com.google.android.gms.maps.SupportMapFragment ...> (Pick Layout ...)
 Do not warn about <fragment> tags in this session.

Does anyone have a solution?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />
like image 615
Vinicius Siqueira Avatar asked Feb 20 '26 10:02

Vinicius Siqueira


2 Answers

The issue here is that the Android studio IDE does not know which fragment to insert in the layout editor because the fragment is inserted at run time.

To resolve, follow these steps (the steps below are for a Sceneform fragment example but same principle applies for other fragments)

  • If you look at the layout editor you should see a red error warning in the top right (Android studio 4.0).

enter image description here

  • Click on this and you will see an error message as you have described above.

enter image description here

  • Click on the pick layout link and you should see a list of layouts.

enter image description here

  • Choose the one that you are using and click on it.

  • Android studio will add a line to your layout to tell the editor to use this layout in the preview.

The line added will look something like:

<fragment
   android:id="@+id/ux_fragment"
   android:name="com.google.ar.sceneform.ux.ArFragment"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:layout="@layout/sceneform_ux_fragment_layout" />  //This the new line inserted
like image 102
Mick Avatar answered Feb 23 '26 00:02

Mick


Short answer:

Just add this line to fragment tag:

tools:layout="@layout/your_fragment_layout"
like image 41
Milad Faridnia Avatar answered Feb 22 '26 23:02

Milad Faridnia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!