2

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?

pseusys
  • 407
  • 2
  • 5
  • 17
  • Both of them call `onInflate()` on the Fragment and pass the values through. Does that method get called for your `MapFragment` class? – ianhanniballake Mar 05 '21 at 00:35
  • @ianhanniballake It does, and I also checked which attributes are passed to it in `AttributeSet` parameter: in both cases all specified attributes are passed correctly. – pseusys Mar 05 '21 at 00:59
  • So it doesn't sound like a problem with `FragmentContainerView` at all then? – ianhanniballake Mar 05 '21 at 01:44
  • @ianhanniballake no, its not about any problem. It's about possibility. Is it possible to make it work as expected with `FragmentContainerView `? And if yes, what to do for it? – pseusys Mar 05 '21 at 02:06
  • Well if the attributes are being passed to the `SupportMapFragment`, I'm confused what your problem is? It seems like it *is* working according to what you are saying? – ianhanniballake Mar 05 '21 at 03:38
  • @ianhanniballake, the attributes are passed, but the map is not modified the way it is expected. For example, `cameraZoom` is passed in `onInflate()` method, but the zoom does not change, it remains default. Unlike in case with `fragment` tag. My question is why. – pseusys Mar 05 '21 at 12:43

0 Answers0