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