Android MapView在ViewPagerIndicator中没有缩放/平移功能

时间:2012-11-22 19:51:00

标签: android android-mapview zoom pan viewpagerindicator

我尝试在ViewPageIndicator库的TabPageIndicator中显示MapView。 要在片段中使用MapView,请使用android-support-v4-r10.googlemaps.jar。

到目前为止,我可以显示MapView,但它不会对Touch-Events做出反应。我不能放大或平移......

我的MapFragment:

@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>

FragmentActivity:

                ...
        //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;
}

1 个答案:

答案 0 :(得分:0)

我认为MapView.setClickable()的默认值为false。

尝试以下方法:

if(mapView == null){
    mapView = new MapView(this, "my-googlemaps-key...");
    mapView.setClickable(true); //add this line
}

问候。