In my app I used a FragmentContainerView
to keep a single fragment, extended from SupportMapFragment
.
Just like this:
<androidx.fragment.app.FragmentContainerView
android:name="com.package.name.fragments.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Reading the docs about SupportMapFragment I found out, that it is possible to set up its initial state using xml attributes (Like here, or even more important, like here). However, adding these attributes to FragmentContainerView
does not affect map.
So, the following code doesn't work as expected:
<androidx.fragment.app.FragmentContainerView
android:name="com.package.name.fragments.MapFragment"
android:id="@+id/map"
map:cameraTargetLat="11"
map:cameraTargetLng="10"
map:cameraZoom="10.0"
map:mapType="normal"
map:mapId="@string/google_maps_style"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The style is not set, nor does the latitude, longitude or zoom. The only workaround I found is:
<fragment
class="com.package.name.fragments.MapFragment"
android:id="@+id/map"
map:cameraTargetLat="11"
map:cameraTargetLng="10"
map:cameraZoom="10.0"
map:mapType="normal"
map:mapId="@string/google_maps_style"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This one works as expected, but as far as I know FragmentContainerView
was made to replace fragment
tag. So the question is, is it possible to pass XML attributes to the fragment, contained in FragmentContainerView
?
EDIT:
Thanks to @ianhanniballake I found out that in both cases attributes are passed to the onInflate()
method of the fragment correctly. But it doesn't solve the main problem, why the parameters specified by these attributes (such as camera latitude, longitude or zoom) are finally set if the fragment was defined in fragment
tag and are not - if in FragmentContainerView
tag?
Long story short, why isn't map in FragmentContainerView
initialized with XML attributes correctly?