1

I am working on an application in which i am getting a map in full screen and also action bar on the top. In action bar i have also included Navigation drawer. Everything is working fine but the Button is not getting displayed onto the MapView.
If I remove the navigation drawer functionality, the buttons are getting displayed. But my requirement is like i should be able to display the button on the bar as well as the Navigation bar.

The snippets are:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mobile.android.ui.MapActivity"
    tools:ignore="MergeRootFrame" >

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="List"
        android:layout_marginRight="20dip"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="20dip"
        android:layout_gravity="left|top" />
<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
 <fragment android:id="@+id/navigation_drawer"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:name="com.mobile.android.ui.NavigationDrawerFragment" />
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
anand
  • 1,711
  • 2
  • 24
  • 59
  • Did you seen this posting? http://stackoverflow.com/questions/14694119/how-to-add-buttons-at-top-of-map-fragment-api-v2-layout – Martin Pfeffer Oct 07 '14 at 12:59
  • yeah! I have seen this post.. I am getting the buttons if i exclude the navigation drawer code ! My requirement is like in my screens I want both Navigation drawer and buttons on the map ...!@Martin Pfeffer – anand Oct 07 '14 at 13:01
  • Hmm, I couldn't imagine how it should work. Do you mean really mean the NavigationDrawer and not the ViewPager? The focus get's lost if the NavigationDrawer is shown up on the left/right side of the screen. – Martin Pfeffer Oct 07 '14 at 13:05
  • yes, I am also feeling the same thing... the button is getting lost on opening navigation drawer.So i should remove the navigation drawer – anand Oct 07 '14 at 13:13
  • Okay, I will look into my code post it as answer, maybe you can find a way to solve the problem with it... But I'm just a beginner. – Martin Pfeffer Oct 07 '14 at 13:43

1 Answers1

1

My project supports similar features.. But I'm using the ViewPager.

So my location_framgment.xml (see down below) is able show the map and I will display it by the ViewPager's default behaviour. The xml file looks as follow:

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

    <fragment
        android:id="@+id/location_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

</RelativeLayout>

And here my LocationFragment, which extends Fragment

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (sView != null) {
            ViewGroup parent = (ViewGroup) sView.getParent();
            if (parent != null) {
                parent.removeView(sView);
            }
        }

        try {
            sView = inflater.inflate(R.layout.location_fragment, container, false);
            sMap = ((MapFragment) MainActivity.sFragmentManager.findFragmentById(R.id.location_map)).getMap();      
        } catch (InflateException e) {
        Log.d(TAG, "InflateExc.: "+e);
        }

        return sView;
    }
Martin Pfeffer
  • 12,471
  • 9
  • 59
  • 68
  • ..Thanx for the suggestion i will try this approach.. if you are able to find the approach to do with Navigation drawer .. just post your answer – anand Oct 07 '14 at 13:48