mbuna

Adding a mapView to a LinearLayout results in a blank map

Discussion created by mbuna on Jan 23, 2012
Latest reply on Sep 17, 2015 by hassanjamil_magma
When I create a mapView as per the API docs and setContentView(mapView), everything works as expected.

However, I need to show a header and footer as well, so I've set up a layout in my main.xml like this:

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

    <!-- HEADER -->
    <include android:id="@+id/top_header"
        android:layout_alignParentTop="true" layout="@layout/window_title" />


    <!-- FOOTER -->
    <LinearLayout android:id="@+id/bottom_menu"
        android:layout_width="fill_parent"
        android:layout_height="40dp"   
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:background="#333333"
        android:gravity="center_horizontal">
        <!-- menu bar -->
  <Button
   android:id="@+id/btn_edit_feature"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   android:text="@string/btn_edit_feature"
   android:onClick="chooseFeatureLayer" />

        <!-- <include layout="@layout/layout_footer_menu" /> -->
    </LinearLayout>

    <!-- MAIN PART -->
    <LinearLayout android:id="@+id/map_container"
     android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/top_header"
        android:layout_above="@id/bottom_menu"
        android:layout_weight="1"
        android:padding="5dp"
        android:background="#550000">
    </LinearLayout>
</RelativeLayout>


and then I try to show the mapView in "map_container" with this:

mapView = new MapView(this);
mapContainer = (LinearLayout) findViewById(R.id.map_container);
mapContainer.addView(mapView);
setContentView(R.layout.main);


It show's the red background of the LinearLayout (5dp of padding), but the map area is black, and mapView.isLoaded() returns false on a button press. Is there something built into MapView that means it will only initialize if it's displayed via setContentView?

Outcomes