使用Google map api v2時,發生了一個大問題,程式中的map view不是佔據整個頁面,只是其中的一部分。這樣問題就來了,當滾動(Scrolling)時原本map view的位置就會產生殘影,整個畫面就被破壞掉了。(後來發現如果將Google Map View放在ViewPager,也會有類似的問題)
Google了一下,解決方法其實很簡單,也很髒,只要在MapView上,放上一層透明的View就可以。我想是因為V2的map view是使用openGL來繪圖的緣故,會造成redraw區域和傳統的redraw的不同,所以在上面放上一層透明的標準view,讓它可以重畫就行了。真的夠髒,但是夠實際。;-)
<!-- map -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
>
<fragment
android:id="@+id/map_frg"
android:name="com.itraveltech.m1app.pages.childs.GMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- to avoid google map's scrolling problem -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent" />
</RelativeLayout>
沒有留言:
張貼留言