2013-08-02 5 views
0

다음 코드는 하나의 방향으로 잘 작동하지만 곧 방향이 변경으로 예외를 발생합니다SupportMapFragment는 방향 변경에 예외가 발생

using Android.App; 
using Android.Content.PM; 
using Android.Gms.Maps; 
using Android.Gms.Maps.Model; 
using Android.OS; 
using Android.Support.V4.App; 
using Cirrious.MvvmCross.Droid.Fragging; 
using System; 
using System.Collections.Generic; 
using System.Drawing; 

namespace Demo.Droid.Views 
{ 
    [Activity(Label = "View for MapViewModel", Theme = "@android:style/Theme.NoTitleBar", ConfigurationChanges = ConfigChanges.Orientation)] 
    public class MapView : MvxFragmentActivity 
    { 
     private SupportMapFragment _mapFragment; 

     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
      SetContentView(Resource.Layout.MapView); 

      InitMapFragment(); 
     } 

     private void InitMapFragment() 
     { 
      _mapFragment = SupportFragmentManager.FindFragmentByTag("map") as SupportMapFragment; 
      if (_mapFragment == null) 
      { 
       GoogleMapOptions mapOptions = new GoogleMapOptions() 
        .InvokeMapType(GoogleMap.MapTypeNormal) 
        .InvokeZoomControlsEnabled(false) 
        .InvokeCompassEnabled(true); 

       FragmentTransaction fragTx = SupportFragmentManager.BeginTransaction(); 
       _mapFragment = SupportMapFragment.NewInstance(mapOptions); 

       fragTx.Add(Resource.Id.map, _mapFragment, "map"); 
       fragTx.Commit(); 
      } 
     } 
    } 
} 

내가 한 OnCreate에서 InitMapFragment을 주석 경우지도로드 및 올바르게 회전하므로 SupportMapFragment와 관련이있는 것으로 보입니다.

레이아웃 파일에는 다음이 포함

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:background="@drawable/nav_bar_background" 
     android:id="@+id/bartop"> 
    </RelativeLayout> 
    <fragment 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.8" 
     android:id="@+id/map" /> 
    <RelativeLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/barbottom" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/nav_bar_background"> 
    </RelativeLayout> 
</LinearLayout> 

디버깅 출력은 단지 보여줍니다 '처리되지 않은 예외가 발생했습니다.' 하지만 장치 로그를 보여줍니다

android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
(raw stack trace not found) 
Caused by: 
java.lang.IllegalStateException: Fragment com.google.android.gms.maps.SupportMapFragment did not create a view. 
+0

예외는 무엇입니까? – Cheesebaron

+0

OnCreate의 InflateException입니다. 질문에 세부 사항을 추가했습니다. – Neil

답변

1

나는 조각이 프로그래밍 방식으로 수정 여전히 오류의 원인을 모르겠어요,하지만 XML의 FrameLayout이로 조각을 변경 한 다음 추가. 레이아웃 파일과

using Android.App; 
using Android.Content.PM; 
using Android.Gms.Maps; 
using Android.Gms.Maps.Model; 
using Android.OS; 
using Android.Support.V4.App; 
using Cirrious.MvvmCross.Droid.Fragging; 
using System; 
using System.Collections.Generic; 
using System.Drawing; 

namespace Demo.Droid.Views 
{ 
    [Activity(Label = "View for MapViewModel", Theme = "@android:style/Theme.NoTitleBar", ConfigurationChanges = ConfigChanges.Orientation)] 
    public class MapView : MvxFragmentActivity 
    { 
     private SupportMapFragment _mapFragment; 

     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 

      _mapFragment = new SupportMapFragment(); 
      var fragmentTx = this.SupportFragmentManager.BeginTransaction(); 
      fragmentTx.Add(Resource.Id.mapFrame, _mapFragment); 
      fragmentTx.Commit(); 

      SetContentView(Resource.Layout.MapView); 
     } 
    } 
} 

: 그 레이아웃이 단편을 포함 할 때 조각으로 레이아웃을 부풀려 수 없습니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:background="@drawable/nav_bar_background" 
     android:id="@+id/bartop"> 
    </RelativeLayout> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.8" 
     android:id="@+id/mapFrame" /> 
    <RelativeLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/barbottom" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/nav_bar_background"> 
    </RelativeLayout> 
</LinearLayout> 
0

. 중첩 된 조각은 조각에 동적으로 추가 될 때만 지원됩니다. 따라서 프래그먼트를 프로그램 적으로 추가하십시오.

관련 문제