3


我需要顯示谷歌地圖的圓形狀,如下圖所示。

Map in circle

我現在使用的解決方案是這樣的:Android谷歌地圖圓形

<packagename.views.SquareWidthRelativeLayout 
       android:id="@+id/map_wrapper" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <fragment 
        android:id="@+id/map_fragment" 
        android:name="com.google.android.gms.maps.SupportMapFragment" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"/> 

       <RelativeLayout 
        android:id="@+id/map_button" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@drawable/map_round_border" 
        android:clickable="true" 
        android:focusable="true"></RelativeLayout> 

      </packagename.views.SquareWidthRelativeLayout> 


所以其實我只是用繪製圓形PNG相對佈局的新層重疊的。此解決方案工作正常,看起來不錯。不幸的是,現在我必須在整個佈局下顯示背景圖片。所以我的解決方案在這種情況下不起作用,因爲它具有白色背景圖像,將疊加在主背景之上。

有沒有其他解決方案如何實現這個結果,而不使用可繪製的覆蓋層?

回答

0

創建一個custom view - 一個圓。將其用作子視圖。 Here是一個教程。將地圖片段放入此視圖中。

然後將ImageView放在RelativeLayout中的此自定義視圖之前,如this answer中所述。

+0

你好,謝謝你的建議。不幸的是,我無法將地圖片段放入此圓形視圖中。如果您有任何提示如何操作,我將非常高興。 – Sandak 2015-04-08 17:38:54

+0

當然,你可以在這裏找到它:https://code.google.com/p/gmaps-api-issues/issues/detail?id=5064。如果你還有一些困難,讓我知道。 – KayAnn 2015-04-08 17:48:12

+0

這是嵌套,如果你想詳細瞭解整個概念,請點擊這裏一直到底部:https://github.com/codepath/android_guides/wiki/Creating-and-Using-Fragments – KayAnn 2015-04-08 17:58:56