Adding a mapView to a LinearLayout results in a blank map

7076
3
01-23-2012 09:44 AM
mbunambuna
New Contributor
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?
0 Kudos
3 Replies
mbunambuna
New Contributor
After viewing some other sample apps in the SDK, addView is no good, rather add the map via XML:

     <com.esri.android.map.MapView
     android:id="@+id/map"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
    </com.esri.android.map.MapView>


and reference it in your Java:

mapView = (MapView)findViewById(R.id.map);
0 Kudos
JasonHine
Esri Contributor
I encountered a similar issue at 10.2.0: I had a MapView defined in XML like this:

<com.esri.android.map.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        mapoptions.MapType="Streets"
        mapoptions.ZoomLevel="3"
        mapoptions.center="39.774769, -96.064453" />

When I ran the app, the Streets basemap did not display, just a grid. On pan or zoom, the basemap appeared as expected.  I was able to work around the issue by changing "fill_parent" to "match_parent" for both the MapView layout's width and height:

<com.esri.android.map.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        mapoptions.MapType="Streets"
        mapoptions.ZoomLevel="3"
        mapoptions.center="39.774769, -96.064453" />
0 Kudos
HassanJamil
New Contributor II

I am also facing the similar issue. In my case, I am using Fragments which contain MapViews in their xml layouts of different screen dimension according to my app's design.
Only the MapView is working for the fragment which is loaded first. Other Fragment's MapViews (when initiated) are just showing the reflection of initiated MapView (of firstly loaded fragment). But when I get my app's resume state back after having its pause the MapView of the other fragment (top fragment of back stack) is working fine as it should be.

Tried alot to come over this issue but still having it, can anybody please help me out?
It will be more than appreciated.

MapView's second xml layout is not working properly when adding its fragment

0 Kudos