我有一个Android应用程序的xamarin。我想在一个标签上添加带标签和谷歌地图的ActionBar。
当我点击地图标签时,它只能工作一次。
我解释一下,推出的应用程序,我在事件选项卡上,我点击地图标签,地图正常工作,但当我回到事件标签并再次映射标签时,它会崩溃。
主要
ActionBar.SetDisplayShowHomeEnabled (true);
ActionBar.SetDisplayShowHomeEnabled (true);
ActionBar.SetDisplayShowTitleEnabled (true);
ActionBar.SetTitle (Resource.String.app_name);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
SetContentView (Resource.Layout.Main);
var fragMap = new MapPageFragment();
ActionBar.Tab tab2 = ActionBar.NewTab();
tab2 = ActionBar.NewTab();
tab2.SetText("Map");
tab2.TabSelected += delegate(object sender, ActionBar.TabEventArgs e)
{
e.FragmentTransaction.Replace(Resource.Id.fragment_container, fragMap);
};
ActionBar.AddTab(tab2);
MapPageFragment:
namespace OnmappTest
{
public class MapPageFragment : Android.App.Fragment
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
view = inflater.Inflate(Resource.Layout.MapPage, container, false);
错误
二进制xml文件行#1:错误膨胀类片段“on”view = inflater.Inflate(Resource.Layout.MapPage,container,false);
MapPage
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="350dp"
class="com.google.android.gms.maps.MapFragment" />
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="OnmappTest.OnmappTest">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="21" />
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- We need to be able to download map tiles and access Google Play Services-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow the application to access Google web-based services. -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:label="OnmappTest" android:icon="@drawable/icon">
<!-- Put your Google Maps V2 API Key here. -->
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="value" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
我尝试SupportMapFragment
代替MapFragment
,FragmentActivity
而不是片段但没有
答案 0 :(得分:0)
我遇到了同样的问题。请将此添加到OnPause方法:
protected override void OnPause()
{
base.OnPause();
if (_mapFragment != null)
{
FragmentManager fragmentManager = FragmentManager;
fragmentManager.BeginTransaction().Remove(_mapFragment).Commit();
}
}
这解决了我的问题,希望能解决你的问题。