Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DrawerLayout with Google Maps

I am having an issue with Google's DrawerLayout when it is placed in an activity with a map fragment. I have not tried with a MapView, however I fear the problem would remain the same.

I am using google's DrawerLayout from the support library (v13), and placing a map within it.

The problem I have is better explained through images... On 2.2-2.3 (fine on 4.0+) the drawer doesn't appear if it's over wherever the google map fragment is drawn. The remainder of the view, along with widgets on the view get shaded properly, but not the map.

Here is my xml layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:weightSum="4">
        <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="3"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:scrollingCache="false"
                map:cameraTargetLat="39.828325"
                map:cameraTargetLng="-98.579728"
                map:cameraZoom="2"
                map:cameraTilt="0"
                map:cameraBearing="0"/>
        <LinearLayout
                android:id="@+id/map_fragmentHolder"
                android:layout_height="0dp"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_weight="1" />
    </LinearLayout>
    <include
        layout="@layout/menu_layout"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_gravity="start" />

</android.support.v4.widget.DrawerLayout>

Here is what is seen on 2.x devices, the screenshot is taken within the Android debug monitor, and the square should be one of my DrawerLayout's buttons

Android 2.x

This is how it should look:

Android 4.x

I have fears that this is caused by the fact that the Gmaps object is drawn on a FrameLayout, but I don't really know.

Anybody run into this issue or have ideas on how to resolve? Thanks.

like image 979
Doge Avatar asked Jun 14 '13 15:06

Doge


People also ask

How to add DrawerLayout in Android?

The drawer icon is displayed on all top-level destinations that use a DrawerLayout . To add a navigation drawer, first declare a DrawerLayout as the root view. Inside the DrawerLayout , add a layout for the main UI content and another view that contains the contents of the navigation drawer.

What is MapFragment?

public class MapFragment extends Fragment. A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.

What is Navigation drawer?

Android Navigation Drawer is a sliding left menu that is used to display the important links in the application. Navigation drawer makes it easy to navigate to and fro between those links. It's not visible by default and it needs to opened either by sliding from left or clicking its icon in the ActionBar.


1 Answers

I ran into this issue and I attempted this solution: https://stackoverflow.com/a/16231935/267559. It worked for me. Please give it a try.

like image 110
Shiun Avatar answered Sep 23 '22 12:09

Shiun