ViewPager에서로드하려고하는 MapView 컨트롤이 있습니다. ViewPager 자체는 조각 내에 있으며 조각 시나리오 내에서 조각을 피하기 위해 ViewPager는 조각이 아닌 레이아웃보기로로드됩니다. ViewPager가 그렇게 다음 화면을로드해야로서,MapView 컨트롤이 ViewPager 내에서로드되지 않습니다.
public class AmbientPagerAdapter : PagerAdapter {
private ViewPagerWithMap pager;
private CurrentLocationStatistics ambientData;
private AmbientSearchBuilder searchBuilder;
private AmbientSearchIndicatorBuilder searchIndicatorBuilder;
private AmbientIndicatorBuilder indicatorBuilder;
private AmbientMapBuilder mapBuilder;
private Bundle savedInstanceState;
public AmbientPagerAdapter(View view, CurrentLocationStatistics ambientData, Bundle savedInstanceState) {
this.pager = view.FindViewById<ViewPagerWithMap> (Resource.Id.ambient_pager);
this.ambientData = ambientData;
this.savedInstanceState = savedInstanceState;
SetupEvents();
}
private void SetupEvents() {
pager.Touch += (object sender, View.TouchEventArgs e) => {
pager.Parent.RequestDisallowInterceptTouchEvent(true);
e.Handled = false;
};
}
#region Setup Views
public override Java.Lang.Object InstantiateItem(View collection, int position) {
var layoutInflater = (LayoutInflater)ApplicationContext.Activity.GetSystemService (Context.LayoutInflaterService);
View view = null;
switch (position) {
case 0:
view = layoutInflater.Inflate (Resource.Layout.AmbientSearch, null);
searchBuilder = new AmbientSearchBuilder (view, ambientData);
break;
case 1:
view = layoutInflater.Inflate (Resource.Layout.AmbientSearchIndicators, null);
searchIndicatorBuilder = new AmbientSearchIndicatorBuilder (view, ambientData);
break;
case 2:
view = layoutInflater.Inflate (Resource.Layout.AmbientIndicators, null);
indicatorBuilder = new AmbientIndicatorBuilder (view, ambientData);
break;
case 3:
view = layoutInflater.Inflate (Resource.Layout.AmbientMap, null);
mapBuilder = new AmbientMapBuilder (view, ambientData, savedInstanceState);
break;
}
// Add view to pager
var viewPager = collection.JavaCast<ViewPager>();
viewPager.AddView(view);
return view;
}
public void Update (CurrentLocationStatistics ambientData) {
this.ambientData = ambientData;
if (searchBuilder != null) {
searchBuilder.Update (ambientData);
}
if (searchIndicatorBuilder != null) {
searchIndicatorBuilder.Update (ambientData);
}
if (indicatorBuilder != null) {
indicatorBuilder.Update (ambientData);
}
if (mapBuilder != null) {
mapBuilder.Update (ambientData);
}
}
#endregion
#region Infrastructure
public override void DestroyItem(View collection, int position, Java.Lang.Object view) {
var viewPager = collection.JavaCast<ViewPager>();
viewPager.RemoveView (view as View);
if (position == 3 && mapBuilder != null) {
mapBuilder.OnDestroy();
}
}
public override bool IsViewFromObject(View view, Java.Lang.Object obj) {
return view == obj;
}
public override IParcelable SaveState() {
return null;
}
public override void StartUpdate(View arg0) {
}
public override void FinishUpdate(View arg0) {
}
public void UpdateVisibleItem (int index) {
pager.SetCurrentItem (index, false);
}
public override int Count {
get {
return 4;
}
}
#endregion
public AmbientSearchBuilder SearchBuilder { get { return searchBuilder; } }
public AmbientMapBuilder MapBuilder { get { return mapBuilder; } }
}
사용자가지도를 인스턴스화 3 화면으로 스 와이프하면 다음과 같습니다
는 4 화면으로지도를로드 ViewPager의 어댑터입니다 (기본 ViewPager 동작입니다.) 이것이 문제의 일부가 될 수 있으며, 아직보기에 없을 때지도를로드하고 있습니까?아래는 MapView를 설정하는 클래스입니다. 라이프 사이클 이벤트는 ViewPager를 호스팅하는 프래그먼트에 의해 호출됩니다. 다음은
<RPR.Mobile.Droid.Widget.TouchMapView xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
map:cameraTargetLat="37.09024"
map:cameraTargetLng="-95.712891"
map:cameraZoom="3"
map:uiCompass="false"
map:uiRotateGestures="false"
map:uiScrollGestures="true"
map:uiTiltGestures="false"
map:uiZoomGestures="true"
map:uiZoomControls="false"
android:layout_width="match_parent"
android:layout_height="match_parent" />
, 그냥 그리드 라인과 회색 배경 있지만지도를 보여줍니다 같은지도가 어떻게 생겼는지되고 :
public class AmbientMapBuilder : AmbientBuilderBase {
private View view;
private TouchMapView mapView;
private PropertyMapAdapter adapter;
private Geolocation initialLocation;
private CameraPosition lastCamera;
private TinyMessageSubscriptionToken filterToken;
public AmbientMapBuilder(View view, CurrentLocationStatistics ambientData, Bundle savedInstanceState = null) : base(ambientData) {
this.view = view;
this.mapView = view.FindViewById<TouchMapView> (Resource.Id.map);
mapView.OnCreate (savedInstanceState);
//MapsInitializer.Initialize (ApplicationContext.Activity);
}
public void Update (CurrentLocationStatistics ambientData) {
this.ambientData = ambientData;
}
#region Lifecycle Events
public void OnResume() {
if (mapView != null)
mapView.OnResume();
if (lastCamera != null) {
if (adapter != null)
adapter.MoveMapToPosition (lastCamera);
lastCamera = null;
}
}
public void OnPause() {
mapView.OnPause();
lastCamera = mapView.Map.CameraPosition;
if (filterToken != null) {
filterToken.Dispose();
filterToken = null;
}
}
public void OnSaveInstanceState (Bundle outState) {
var map = mapView;
if (map != null)
map.OnSaveInstanceState (outState);
}
public void OnLowMemory() {
if (mapView != null) {
mapView.OnLowMemory();
}
}
public void OnDestroy() {
if (mapView != null) {
mapView.OnDestroy();
}
}
#endregion
public bool MapIsLoaded { get; set; }
public PropertyMapAdapter MapAdapter {
get { return adapter; }
}
public View View {
get { return view; }
}
public TouchMapView MapView {
get { return mapView; }
}
}
그리고 마지막으로,이지도의 레이아웃 XML입니다 지도는 상호 작용할 수 없습니다.
문제가 무엇인지 어떤 아이디어?