Google Map api 2 how to show/hide GoogleMap?

人盡茶涼 提交于 2019-12-06 11:20:19

问题


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


回答1:


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();



回答2:


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);
}


来源:https://stackoverflow.com/questions/16936624/google-map-api-2-how-to-show-hide-googlemap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!