I am observing unexpected behavior of Google Map. Problem is Map getting crop from top and bottom area using Support Map Fragment, if I am using full screen, map is completely visible as shown in Picture 1, but if I am applying map fragment height or weight property, map is not completely visible as shown in Picture 2.
layout xml for picture 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" />
layout xml for picture 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 Picture 2, I am(User will be) unable to see arctic ocean above Greenland area, similarly bottom area region will be missing, as shown in Picture 3.
Did anyone face this issue or does anyone know how to cope up it with?
Any reference link or hint will be kindly appreciated.
, .
Use this snippet. I got what you were saying, by taking the map fragment inside Linear/Relative layout, the map gets cut from top and bottom and some portions are not visible. Since you want map to take 60% of the screen one possible solution is, take the map fragment inside FrameLayout with height as match_parent.
Now, take the textview inside LinearLayout with parent as FrameLayout and set its gravity to be bottom and set its height dynamically 40% of the screen(or how much your requirement is) by using the DisplayMetrics class. By this way, we are ensuring that the full screen is provided to the map so that no portion gets cut, and displaying the text also above the map. I'm attaching the updated screenshot also.
<?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));
I think this will help.
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