【问题标题】:Error inflating class fragment with class using FragmentActivity使用 FragmentActivity 用类膨胀类片段时出错
【发布时间】:2014-05-18 06:44:06
【问题描述】:

我在Xamarin 中编写了一个Google Maps 应用程序,并收到此错误:

Android.Views.InflateException:二进制 XML 文件第 1 行:错误 膨胀类片段

运行以下代码行时出现此错误:

SetContentView(Resource.Layout.MapWithOverlayLayout);

这是我的MapWithOverlayLayout.axml 布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
  <fragment class="SimpleMapDemo.MapWithMarkersActivity"
            android:id="@+id/mapWithOverlay"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
</LinearLayout>

命名空间被调用:SimpleMapDemo

这是我的班级声明:

public class MapWithMarkersActivity : Android.Support.V4.App.FragmentActivity

我正在使用 SupportMapFragment 对象来显示 Google 地图

能否请我帮忙让这段代码正常工作?

【问题讨论】:

    标签: android-layout android-fragments xamarin android-fragmentactivity inflate-exception


    【解决方案1】:

    我认为问题在于您在片段元素上设置的类属性。您是否厌倦了没有它的布局?

    【讨论】:

      【解决方案2】:

      我自己想通了。我没有正确的类名。

      这是正确的布局代码:

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

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题,并通过在 VS 或 XS 中删除 obj/Debug/android 目录中的 AndroidManifest 并重写它来修复它,使其仅适用于我

        这是因为应用无法区分 google play services manifest 和应用的清单。

        【讨论】:

          猜你喜欢
          • 2014-04-11
          • 1970-01-01
          • 2011-09-19
          • 2013-05-28
          • 1970-01-01
          相关资源
          最近更新 更多