2

I have a scroll view inside which there is a relative layout containing a flexible sized content on top and a map view below it. If the entire content's height is smaller than the screen view port (Scroll View), I wanted the map view to fill the remaining space below. If the entire content is larger than screen view port then I wanted the map view to have at least a certain height. This is a stripped version of what I have done.

<ScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/flexContent"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_alignParentTop="true"
            android:background="#086dd9"
            android:gravity="center"
            android:text="Flexible content here"
            android:textColor="@android:color/white"
            android:textSize="22sp" />

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_below="@id/flexContent"
            android:background="#f73f3f"
            android:minHeight="120dp"
            map:mapType="normal"
            tools:ignore="MissingPrefix" />
    </RelativeLayout>


</ScrollView>

It works as expected when the entire content's height is smaller than the screen view port's height (Scroll view's height). However, when it is not, everything works good except the map is not loading to the mapview's full height. Please take a look at the images below

Content smaller than scroll view enter image description here

Content larger than scrollview

enter image description here

As you can see in the second picture, the map view itself is respecting the minHeight 120dp constraint set in the layout (I have made the background of the map view red) but the actual map is not loading to its full height.

How can this be fixed?

Much Overflow
  • 3,142
  • 1
  • 23
  • 40
  • Take a look at this: http://stackoverflow.com/questions/29956014/why-should-we-use-xml-layouts – Nanoc Nov 26 '15 at 09:24

1 Answers1

2

I fixed the above problem by wrapping the MapView inside a LinearLayout. My final layout looks something similar to this now. Hope it helps anyone in the future :)

<ScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/flexContent"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_alignParentTop="true"
            android:background="#086dd9"
            android:gravity="center"
            android:text="Flexible content here"
            android:textColor="@android:color/white"
            android:textSize="22sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_below="@id/flexContent"
            android:orientation="vertical"
            android:minHeight="120dp">

            <com.google.android.gms.maps.MapView
                android:id="@+id/mapView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#f73f3f"
                map:mapType="normal"
                tools:ignore="MissingPrefix" />

        </LinearLayout>

    </RelativeLayout>

</ScrollView>
Much Overflow
  • 3,142
  • 1
  • 23
  • 40
  • In my case, that helped http://stackoverflow.com/questions/32908988/android-map-loading-very-slow-not-loading-at-all-in-started-activity-until-click Just in case this doesn't help for anyone. – Heitor Colangelo Jun 06 '16 at 19:37
  • Thank you very much!! This helped me a lot!! – Sabina Oct 17 '18 at 17:03