微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

谷歌地图v3 MapView没有采用Android中的所有父视图

我正在使用一个名为GoogleMapFragment的片段来显示Google Map(v3)MapView.这是片段本身正在使用的布局,然后插入到另一个布局中:

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

父布局是:

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

    <!-- Overview section -->
    <LinearLayout
        android:id="@+id/games_overview_wrapper"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <!-- Details section -->
    <LinearLayout
        android:id="@+id/games_detail_wrapper"
        android:orientation="vertical"
        android:minHeight="@dimen/node_game_details_min_height"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <!-- Map section -->
    <FrameLayout
        android:background="#d40707"
        android:id="@+id/games_location_fragment_wrapper"
        android:minHeight="@dimen/node_game_details_min_height"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Photos section -->
    <FrameLayout
        android:id="@+id/games_gallery_fragment_wrapper"
        android:minHeight="@dimen/node_game_details_min_height"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

各个“部分”永远不会同时显示,但会根据其他事件隐藏和显示. game_location_fragment_wrapper是插入MapView的布局.

在“Game”片段中,我正在插入GoogleMapFragment:

// Setup the Google Maps fragment
if (node.hasLocation(getActivity())) {
    GoogleMapsFragment googleMapsFragment = new GoogleMapsFragment();
    googleMapsFragment.setNode(node);
    googleMapsFragment.addLocations(node);

    getChildFragmentManager()
            .beginTransaction()
            .replace(R.id.games_location_fragment_wrapper, googleMapsFragment, node.getValue(NODE_KEY.TITLE))
            .commit();
} else {
    locationIv.setVisibility(View.GONE);
    gamesLocationFragmentWrapper.setVisibility(View.GONE);
}

一切都可以工作,但是MapView没有占用所有的父视图,然后在显示后一瞬间导致java.lang.IllegalStateException:填充Exception后视图大小太小.

enter image description here

在屏幕截图中,红色背景表示包含视图的大小. MapView显然没有采用完整的大小.

有小费吗?

更新:添加了地图片段的相关部分:

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {

    final View view = inflater.inflate(R.layout.fragment_maps, container, false);

    mapView = (MapView)view.findViewById(R.id.map_view);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);

    return view;
}

和…

@Override
public void onMapReady(final GoogleMap googleMap) {

    googleMap.setonInfoWindowClickListener(this);

    final LatLngBounds.Builder bounds = new LatLngBounds.Builder();
    int count = 0;

    for(Node node : relatednodes) {

        try {

            if (node.hasLocation(getActivity())) {

                final double latitude = Double.parseDouble(node.getValue(NODE_KEY.LATITUDE));
                final double longitude = Double.parseDouble(node.getValue(NODE_KEY.LONGITUDE));

                final LatLng latlng = new LatLng(latitude, longitude);
                bounds.include(latlng);

                final MarkerOptions markerOptions = new MarkerOptions().position(latlng).title(node.getValue(NODE_KEY.TITLE));

                Marker marker = googleMap.addMarker(markerOptions);

                markerNodeHashmap.put(marker, node);

                count++;
            }
        } catch (NumberFormatException e) {
            // Double wasn't parsed right. Continue.
        }
    }

    if (count > 0) {
        googleMap.setonMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
            @Override
            public void onMapLoaded() {
                googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), UI.convertDpToPixel(getActivity(), 50)));
            }
        });
    }
}

谢谢!

解决方法:

关于java.lang.IllegalStateException的错误,您可以查看此page:填充后视图大小太小.

您还可以查看此page获取更多信息.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐