I am trying to use SupportMapFragment inside a fragment. When you first start the map is displayed without errors.
But when I execute a transaction with another fragment and after that I return to the card, I get an error of inflating the fragment. But I have no errors when I make a new instance of the fragment that contains the map.
Here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:animateLayoutChanges="true" tools:context=".ui.HomeMapFragment"> <fragment android:id="@+id/map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/footer" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:name="com.google.android.gms.maps.SupportMapFragment" /> <FrameLayout android:id="@+id/footer" android:layout_height="110dp" android:layout_width="match_parent" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:background="@color/colorPrimary"/> </RelativeLayout>
And I create my SupportMapFragment instance in onCreateView as follows:
And I call onMapReady in onActivityCreated:
if (mHolder.supportMapFragment != null) mHolder.supportMapFragment.getMapAsync(this);
Error Log:
FATAL EXCEPTION: main Process: xxx.xxxx.xxxx, PID: 4441 android.view.InflateException: Binary XML file line #8: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at xxx.xxxx.xxxx.ui.HomeMapFragment.onCreateView(HomeMapFragment.java:234) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.popFromBackStack(BackStackRecord.java:971) at android.support.v4.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1670) at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:586) at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:189) at com.xxx.xxx.ui.HomeActivity.onBackPressed(HomeActivity.java:71)
I know that itβs not good to hardcode the fragment inside the fragment layout, but I already tried to accomplish this with frameLayout, but I get a lot more errors
source share