Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图api 2如何显示/隐藏谷歌地图?_Android_Android Maps V2 - Fatal编程技术网

Android 谷歌地图api 2如何显示/隐藏谷歌地图?

Android 谷歌地图api 2如何显示/隐藏谷歌地图?,android,android-maps-v2,Android,Android Maps V2,我想显示/隐藏谷歌地图 GoogleMap googleMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map2)).getMap(); 如何设置setVisibility(View.INVISIBLE)或setVisibility(View.VISIBLE)?您应该隐藏片段本身,或者您可以在SupportMapFragment子类中尝试get

我想显示/隐藏谷歌地图

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

如何设置setVisibility(View.INVISIBLE)或setVisibility(View.VISIBLE)

您应该隐藏片段本身,或者您可以在
SupportMapFragment
子类中尝试
getView().setVisibility(View.INVISIBLE)

从您的活动中:

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

我已经实现了一个切换按钮来显示/隐藏地图。我通过一个简单的布尔函数来监视它,并在包含地图的RelativeLayout上调用show/hide

XML是--


任何人都可以说为什么投反对票?如果答案对你有帮助,你应该接受!检查我的答案,它可能有助于在一个函数中实现java函数,该函数在单击时调用
<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>
//use a boolean map_shown and RL name is map_holder
if(map_shown){
map_holder.setVisibility(1);
}
else
{
map_holder.setVisibility(View.GONE);
}