【问题标题】:Google Map api 2 how to show/hide GoogleMap?Google Map api 2 如何显示/隐藏 Google Map?
【发布时间】:2013-05-31 22:59:50
【问题描述】:
我想显示/隐藏 googleMap。
GoogleMap googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map2)).getMap();
如何设置setVisibility(View.INVISIBLE) OR setVisibility(View.VISIBLE) ??
【问题讨论】:
标签:
android
android-maps-v2
【解决方案1】:
您应该隐藏 Fragment 本身,或者您可以尝试在 SupportMapFragment 子类中使用 getView().setVisibility(View.INVISIBLE)。
来自您的活动:
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction()
ft.hide(mFragment).commit();
【解决方案2】:
我已经实现了一个切换按钮来显示/隐藏地图。我通过简单地使用布尔值对其进行了监控,并在包含地图的相对布局上调用了显示/隐藏。
XML 是--
<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>
在您的 java 代码中--
//use a boolean map_shown and RL name is map_holder
if(map_shown){
map_holder.setVisibility(1);
}
else
{
map_holder.setVisibility(View.GONE);
}