I'm using a fragment named GoogleMapFragment which displays a Google Map (v3) MapView. This is the layout that the fragment itself is using, which is then inserted into another layout:
<?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" />
The parent layout is:
<?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>
The individual "sections" are never visible simultaneously, but are hidden and displayed according to other events. The game_location_fragment_wrapper
is the layout in which the MapView will be inserted.
Inside the "Game" fragment I'm inserting the 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);
}
Everything works per se, but the MapView doesn't take all of the parent view, which then a split second after showing causes a java.lang.IllegalStateException: View size is too small after padding
Exception.
In the screenshot, the red background indicates the size of the containing view. The MapView obviously isn't taking the full size.
Any tips?
Update: Added relevant parts of the map fragment:
@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;
}
and...
@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)));
}
});
}
}
Thanks!
You can check this page regarding your error about java.lang.IllegalStateException: View size is too small after padding.
You can also check this page for more information.
Try the below xml file and play with the visibility of layouts, set the height of the parent or make it match_parent with giving some weight in parent of this layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="200dp"
>
<!-- Overview section -->
<LinearLayout
android:id="@+id/games_overview_wrapper"
android:background="@color/primary_green"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- Details section -->
<LinearLayout
android:id="@+id/games_detail_wrapper"
android:orientation="vertical"
android:background="@color/secondary_blue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<!-- Map section -->
<FrameLayout
android:background="#d40707"
android:id="@+id/games_location_fragment_wrapper"
android:minHeight="200dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Photos section -->
<FrameLayout
android:background="@color/text_grey"
android:id="@+id/games_gallery_fragment_wrapper"
android:minHeight="200dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With