Map溢出到ActionBar中的下一个选项卡上

时间:2013-07-23 23:02:49

标签: android android-actionbar google-maps-android-api-2

我设置了操作栏,并在第一个标签上显示地图。我已禁用第一个选项卡上的滚动,以便用户可以在地图上导航。当用户按下第二个标签时,会出现一个地图形状的大黑方块和前一个地图溢出的小条。

这是图片。不得不手动拿第二个,因为每次我拍摄一个屏幕截图时,黑色都会因某种原因而消失。

enter image description here enter image description here

第一个标签的代码

public static class Map extends Fragment {
    MapView mapView;
    GoogleMap map;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.maptab, container, false);

        // Gets the MapView from the XML layout and creates it
        mapView = (MapView) v.findViewById(R.id.mapview);
        mapView.onCreate(savedInstanceState);

        // Gets to GoogleMap from the MapView and does initialization stuff
        map = mapView.getMap();
        //map.getUiSettings().setMyLocationButtonEnabled(false);
        //map.setMyLocationEnabled(true);
        map.addMarker(new MarkerOptions().position(new LatLng(50.167003,19.383262)));


        // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
        try {
            MapsInitializer.initialize(this.getActivity());
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }

        // Updates the location and zoom of the MapView
        //CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
        //map.animateCamera(cameraUpdate);

        return v;
    }

    @Override
    public void onResume() {
        mapView.onResume();
        super.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }
}

XML文件maptab.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </com.google.android.gms.maps.MapView>

</LinearLayout>

HACK SOLUTION 如果您能想出任何其他方法来解决此问题,请与我们联系

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        // When the given tab is selected, switch to the corresponding page in the ViewPager.
        if(tab.getPosition() == 1){ //If it is the tab next to the map tab, set map invisible
            mapView.setVisibility(View.INVISIBLE);
        } else if(tab.getPosition() == 0 && mapView != null){ //If the map tab is clicked and the map is not null, set map to visible
            mapView.setVisibility(View.VISIBLE);
        }
        mViewPager.setCurrentItem(tab.getPosition());

    }

0 个答案:

没有答案