我尝试在 ViewPageIndicator 库的 TabPageIndicator 中显示 MapView。要在片段中使用 MapView,我正在使用 android-support-v4-r10.googlemaps.jar。
到目前为止,我可以显示 MapView,但它不会对触摸事件做出反应。我无法缩放或平移...
我的地图片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
root = (View) inflater.inflate(R.layout.training_map, container, false);
mapViewContainer = (ViewGroup) root.findViewById(R.id.map_container);
return root;
}
@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);
LoggingHelper.i("", "onActivityCreated");
initTextViews();
mapView = ((TrainingActivity) getActivity()).getMapView();
//Zeigt einen blauen Punkt am derzeitigen Standort an
locationOverlay = new MyLocationOverlay(getActivity(), mapView);
locationOverlay.runOnFirstFix(new Runnable() {
@Override
public void run() {
if(mapController != null){
mapController.animateTo(locationOverlay.getMyLocation());
}
}
});
locationOverlay.enableMyLocation();
mapViewContainer.addView(mapView);
}
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tracking_maps_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible" >
<LinearLayout
android:id="@+id/map_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="onClickLock"
android:src="@android:drawable/ic_lock_lock" />
</RelativeLayout>
片段活动:
...
//Paging Initialisieren
adapter = new TrainingFragmentAdapter(getSupportFragmentManager(), fragments);
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(adapter);
pageIndicator = (TabPageIndicator) findViewById(R.id.indicator);
pageIndicator.setViewPager(viewPager);
...
public MapView getMapView(){
if(mapView == null){
mapView = new MapView(this, "my-googlemaps-key...");
}
return mapView;
}