Samir Mangroliya
Samir Mangroliya

Reputation: 40416

Google Map api 2 how to show/hide GoogleMap?

i want to show/hide googleMap.

GoogleMap  googleMap = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map2)).getMap();

how to set setVisibility(View.INVISIBLE) OR setVisibility(View.VISIBLE) ??

Upvotes: 2

Views: 5182

Answers (2)

Kunal S. Kushwah
Kunal S. Kushwah

Reputation: 893

I have implemented a toggle button to show/hide the map. I monitored it through a simple use of boolean, and show/hide was called on the RelativeLayout which contained the Map.

The XML was--

<RelativeLayout
        android:id="@+id/map_container"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
<FrameLayout
            android:id="@+id/frame_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"


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

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent" />
        </FrameLayout>
</RelativeLayout>

In your java code--

//use a boolean map_shown and RL name is map_holder
if(map_shown){
map_holder.setVisibility(1);
}
else
{
map_holder.setVisibility(View.GONE);
}

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157447

you should hide the Fragment itself, or you can try with getView().setVisibility(View.INVISIBLE) inside the SupportMapFragment subclass.

From your Activity:

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction()
ft.hide(mFragment).commit();

Upvotes: 10

Related Questions