Android GoogleMap v2 is cropped or not fully displayed

I am observing the unexpected behavior of Google Maps. The problem is that the map gets the top and bottom crop using a fragment of the support map, if I use full screen mode, the map will be fully visible, as shown in Figure 1, but if I use the height or weight of the map, the map will not be fully visible. as shown in figure 2.

xml layout for image 1:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.paki.venturedive.awtest.MapsActivity" /> 

xml layout for image 2:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.6" tools:context="com.paki.venturedive.awtest.MapsActivity" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="Hello world" android:layout_weight="0.4" /> 

Java Code:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } 

In Figure 2, I (the User will be) unable to see the Arctic Ocean over the Greenland region, as well as the region of the lower region, will be absent, as shown in Figure 3 enter image description here .

Has anyone come across this problem or does anyone know how to deal with it?

Any links or tips would be kindly appreciated.

Image 1 , Image 2 .

+5
source share
1 answer

Use this snippet. I got what you said, taking a fragment of the map inside the linear / relative layout, the map is cut up and down, and some parts are not visible. Since you want the map to occupy 60% of the screen, one of the possible solutions is to take a fragment of the map inside FrameLayout with a height like match_parent.

Now take the text view inside LinearLayout with the parent as FrameLayout and set its gravity value to the bottom and set it dynamically dynamically to 40% of the screen (or as far as necessary) using the DisplayMetrics class. Thus, we guarantee that the full screen will be provided to the map, so that no part is cut off, and displaying text also above the map. I am also adding an updated screenshot.

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map_framecontainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <fragment android:id="@+id/fragment_map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:id="@+id/tv_main"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/fragment_map" android:layout_gravity="center" android:background="#ffffff" android:text="Hello world" /> </LinearLayout> </FrameLayout> 

The java code in your onCreate for DisplayMetrics:

  DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); mylinearlayout.setMinimumHeight((int)(metrics.heightPixels * 0.4)); 

Screenshot of a full map on top

I think this will help.

+2
source

Source: https://habr.com/ru/post/1246200/


All Articles