Xamarin - 将 ESRI MapView 动态添加到 FrameLayout
Xamarin - Add ESRI MapView dynamically to FrameLayout
我还没有发现任何能够使用 axml 定义从 ArcGIS SDK for Xamarin 添加 MapViewer 的功能。这似乎不可能:
<?xml versio="1.0" encoding="utf-8"?>
<LinearLayout>
...
<com.esri.mapping.MapView ... />
</LinearLayout>
我找到了使用代码动态构建整个视图的示例。 https://github.com/Esri/arcgis-runtime-samples-xamarin/tree/master/src/Android/Xamarin.Android
我更愿意使用 XML 来更灵活地扩展视图,所以我想到将 MapView 动态添加到 FrameLayout - 像这样定义资源 (activity_map.axml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapView" />
</LinearLayout>
然后在 activity class:
public class MainActivity : MvxActivity<MainViewModel>
{
private MapView _mapView = new MapView();
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
_mapView = new MapView(this);
SetContentView(Resource.Layout.activity_amp);
//How to get FrameLayout id ???
var mapContainer=(FrameLayout)FindViewById();
mapContainer.AddView(_mapView);
}
}
这是一种有效的方法吗?你会推荐另一个吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Esri.ArcGISRuntime.UI.Controls.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapView" />
</LinearLayout>
和
public class MainActivity : MvxActivity<MainViewModel>
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
var mapView = (MapView) FindViewById(Resource.Id.mapView);
mapView.Map = ViewModel.Map;
}
}
我还没有发现任何能够使用 axml 定义从 ArcGIS SDK for Xamarin 添加 MapViewer 的功能。这似乎不可能:
<?xml versio="1.0" encoding="utf-8"?>
<LinearLayout>
...
<com.esri.mapping.MapView ... />
</LinearLayout>
我找到了使用代码动态构建整个视图的示例。 https://github.com/Esri/arcgis-runtime-samples-xamarin/tree/master/src/Android/Xamarin.Android
我更愿意使用 XML 来更灵活地扩展视图,所以我想到将 MapView 动态添加到 FrameLayout - 像这样定义资源 (activity_map.axml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapView" />
</LinearLayout>
然后在 activity class:
public class MainActivity : MvxActivity<MainViewModel>
{
private MapView _mapView = new MapView();
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
_mapView = new MapView(this);
SetContentView(Resource.Layout.activity_amp);
//How to get FrameLayout id ???
var mapContainer=(FrameLayout)FindViewById();
mapContainer.AddView(_mapView);
}
}
这是一种有效的方法吗?你会推荐另一个吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Esri.ArcGISRuntime.UI.Controls.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapView" />
</LinearLayout>
和
public class MainActivity : MvxActivity<MainViewModel>
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
var mapView = (MapView) FindViewById(Resource.Id.mapView);
mapView.Map = ViewModel.Map;
}
}