Android MapFragment as custom control in MvvmCross

大兔子大兔子 提交于 2019-12-11 18:02:05

问题


I'm working on a project in which I can use MapFragment or SupportMapFragment as a custom control. I tried to mix custom control(N-18) and Fraggle(N-26) tutorial but I can't make it work.

My Custom Control Class:

public class CustomMapView : MvxFragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var ignored = base.OnCreateView(inflater, container, savedInstanceState);
        return this.BindingInflate(Resource.Layout.CustomMapViewLayout, null);
    }
}

My CustomMapViewLayout.axml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

In the FirstView.axml I reference the CustomMapView:

<cc.CustomMapView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

(I use the ViewNamespaceAbbreviations in the Setup.cs)

When I try to deploy I get these errors:

MvxBind:Error View Type Not Found - cc.CustomMapView (I'm sure the namespace is correct) Android.Views.InflateException:Loading...

Is there anybody who managed to solve this kind problem?


回答1:


As far as I know, fragments have to be used within FragmentActivity parents and have to be loaded either using the fragment xml tag or using one of the (support) fragment manager methods for dynamic loading within a parent viewgroup.

The Mvx code which is reporting View Type Not Found - cc.CustomMapView definitely won't work - it's looking for a class which inherits Android View in that namespace, not looking for a Fragment.

There may be ways to write more 'dynamic' fragment xml code - but none of the mvvmcross contributors have unearthed any of these yet. For now, I think you'll have to use the Fragments more 'conventionally' - like the ways shown in the N=26 sample



来源:https://stackoverflow.com/questions/18079793/android-mapfragment-as-custom-control-in-mvvmcross

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!