Search code examples
androidandroid-mapviewmapactivity

Facebook slide Menu With MapView on Android


so I am aware of a few workarounds to get the facebook slide menu on my android app which can be through either:

1- FrameLayouts (http://stackoverflow.com/a/8673805/1010114)

2- screenshots (http://stackoverflow.com/a/9768498/1010114)

However, what I want to do, and so far clueless on how to achieve, is to have the facebook slide menu in a MapActivity. This way, user can see and interact with the MapView and has the ability to press the menu button to look at the menu (when the menu appears, it's fine if the user can't interact with the visible part of the map)

Using option number 2 (screenshots) did not work because it seems I can't not take screen shots of a mapview (or at least I can't using his way)

Any hints/ideas on how to do that ?


Solution

  • I had the same issue and solved it by adding a TabHost on the Activity. You can set the MapActivity as the tab content and hide the button for it.

    Example code:

    map.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <com.google.android.maps.MapView
            android:id="@+id/mapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true" />
    
    </LinearLayout>
    

    main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
    
        <Button
            android:id="@+id/menu_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="menu" />
    
        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
            </FrameLayout>
        </TabHost>
    
    </LinearLayout>
    

    MyMapActivity.java:

    public class MyMapActivity extends MapActivity
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map);
        }
    }
    

    MyActivity.java:

    public class MyActivity extends TabActivity
    {
        private LayoutInflater inflater;
    
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            inflater = LayoutInflater.from(context);
            // Inflate menu here
    
            // Get the TabHost
            TabHost tabHost = getTabHost();
    
            // Add the button and content
            TabHost.TabSpec spec = tabHost.newTabSpec("myMapTab")
                    .setIndicator("Map")
                    .setContent(new Intent(this, MyMapActivity.class));
            tabHost.addTab(spec);
    
            // Hide the button
            tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE);
    
            MapView mapView = (MapView) tabHost.getTabContentView().getChildAt(0).findViewById(R.id.mapview)
        }
    }
    

    I hope this solves your problem.