我想顯示/隱藏谷歌地圖。谷歌地圖api 2如何顯示/隱藏谷歌地圖?
GoogleMap googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map2)).getMap();
如何設置setVisibility(View.INVISIBLE)OR setVisibility(View.VISIBLE) ??
我想顯示/隱藏谷歌地圖。谷歌地圖api 2如何顯示/隱藏谷歌地圖?
GoogleMap googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map2)).getMap();
如何設置setVisibility(View.INVISIBLE)OR setVisibility(View.VISIBLE) ??
你應該隱藏片段本身,或者你可以用getView().setVisibility(View.INVISIBLE)
嘗試SupportMapFragment
子裏面。
從你的活動:
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction()
ft.hide(mFragment).commit();
這爲我工作!謝謝。 – calbertts
不適合我。 –
我實現了一個切換按鈕顯示/隱藏地圖。我監測它通過一個簡單的使用布爾,並顯示/隱藏叫上載地圖RelativeLayout的。
的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>
在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);
}
實現Java功能在被稱爲上點擊功能<切換按鈕> –
任何一個都可以說爲什麼downvote? –
如果它對你有幫助,你應該接受一個答案! –
檢查我的答案,它可能會幫助 - http://stackoverflow.com/a/43299111/1380032 – Rahul