我想显示/隐藏googleMap。
GoogleMap googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map2)).getMap();
如何设置 setVisibility(View.INVISIBLE)或setVisibility(View.VISIBLE) ??
答案 0 :(得分:10)
你应该隐藏Fragment本身,或者你可以在getView().setVisibility(View.INVISIBLE)
子类中尝试使用SupportMapFragment
。
来自您的活动:
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction()
ft.hide(mFragment).commit();
答案 1 :(得分:0)
我已经实现了一个切换按钮来显示/隐藏地图。我通过简单使用boolean监视它,并在包含Map的RelativeLayout上调用show / hide。
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);
}