2

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) ??

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134

2 Answers2

10

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();
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

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);
}
Kunal S. Kushwah
  • 883
  • 1
  • 8
  • 19