android - MapFragment UI 控制按钮功能正常但不可见

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

解决方案:

解决方案是我之前调用了 zOrderOnTop(true) 来解决 black flickering bug .面对如此多的事件,我猜上述错误目前没有有效的解决方法。我也尝试了线程中的其他建议,但没有一个在不损害应用程序的情况下起作用

原始问题:

在我的应用程序中,我想显示嵌套在另一个 fragment 中的 map fragment ,这对于最新的 API 和支持库来说并不是什么大问题。但是 map 显示了一些奇怪的行为:

Example map image

您可能已经注意到,没有可见的按钮。例如,用于缩放的 plusminus 按钮。而且 myLocation 按钮似乎也不见了。有趣的是:当我点击右上角或右下角的屏幕(您可能知道它们应该在的位置)时,应用程序会完全按照您的预期运行!

因为我只是和the android maps api documentation tutorial一起工作我认为这不是设置可见内容的问题。 我宁愿假设这与我显示 fragment 的方式有关,某些层似乎妨碍了。我该如何解决这个问题?

也许这里有人能指出我的错误,我将不胜感激!

主机 fragment

public class HostFragment extends Fragment {

...

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup res = (ViewGroup) inflater.inflate(R.layout.fragment_map, null);

        // Build the MapFragment as a nested fragment into this one
        mMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentByTag(MAP);
        if (mMapFragment == null) {
            mMapFragment = SupportMapFragment.newInstance(mMapOptions);
            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
            transaction.add(R.id.mapContainer, mMapFragment, MAP).commit();
        }

        // We can't be guaranteed that the map is available because Google Play services might not
        // be available. We'll check this again later on
        setUpMapIfNeeded();

        return res;
    }

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

        // Verify that the map is set up before presenting it to the user
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we haven't already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the MapFragment.
            mMap = mMapFragment.getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
            else {
                LOG.debug("Map is null");
            }
        }
    }

    /**
     * Sets the parameters for the map that will be displayed to the user
     */
    private void setUpMap() {
        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setMyLocationButtonEnabled(true);

        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }
}

宿主布局xml

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </RelativeLayout>

最好的问候

更新:
1: 使用 FrameLayout 而不是 RelativeLayout 不能解决问题
2: 明确地将 map 类型设置为 NORMAL 不会解决问题

最佳答案

尝试修改 setUpMap() 如下:

private void setUpMap() {
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); //added line
    mMap.setMyLocationEnabled(true); 
    mMap.getUiSettings().setMyLocationButtonEnabled(true); //my code did not have these and still be able to display the zoom in, zoom out, and my location button
    mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}

祝你好运!

关于android - MapFragment UI 控制按钮功能正常但不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16810690/

相关文章:

jquery - 电话间隙 : Google Maps' SearchBox/Autocomplete NOT Working on iOS/Mobile

android - Google Maps Api v2 - 具有自己的信息窗口的多个标记

android - Geocoder.getFromLocationName() 在带有 Google Maps V2 的 Android 4 上抛出 "Service not available"异常

java - Android - 安装 Apache Commons VFS - 问题

android - 具有多种项目类型的 ListAdapter 抛出 ClassCastException

javascript - 如何在 Google Maps Javascript API v3 中旋转标记图标图像

Android Polyline - 逐点添加

android - 如何使用 NetBeans IDE 在模拟器上调试 Android 应用程序

android - 是否可以用 Google Pay 替换 Google Play IAB?

android - 获取错误 : java. lang.VerifyError