【问题标题】:Android MapFragment as custom control in MvvmCrossAndroid MapFragment 作为 MvvmCross 中的自定义控件
【发布时间】:2013-08-06 12:10:23
【问题描述】:

我正在开发一个可以使用 MapFragment 或 SupportMapFragment 作为自定义控件的项目。 我尝试混合使用自定义控件(N-18) 和 Fraggle(N-26) 教程,但我无法使其工作。

我的自定义控件类:

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);
    }
}

我的 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" />

在 FirstView.axml 中我引用了 CustomMapView:

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

(我在 Setup.cs 中使用 ViewNamespaceAbbreviations)

当我尝试部署时出现以下错误:

MvxBind:Error View Type Not Found - cc.CustomMapView(我确定命名空间是正确的) Android.Views.InflateException: 加载中...

有没有人设法解决了这种问题?

【问题讨论】:

    标签: xamarin.android xamarin mvvmcross


    【解决方案1】:

    据我所知,片段必须在 FragmentActivity 父级中使用,并且必须使用fragment xml 标记或使用(支持)片段管理器方法之一在父视图组中动态加载。

    报告 View Type Not Found - cc.CustomMapView 的 Mvx 代码肯定不起作用 - 它在该命名空间中寻找继承 Android View 的类,而不是寻找 Fragment

    可能有一些方法可以编写更多“动态”片段 xml 代码 - 但 mvvmcross 贡献者还没有发现任何这些。现在,我认为您必须更“常规”地使用 Fragments - 就像 N=26 sample 中显示的方式一样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多