2011-03-06 90 views
3

我想編寫一個簡單的使用以下佈局的MapActivity(僅包含當前的mapview,因爲我打算在將來添加與ListView共享屏幕):向地圖視圖添加圓角

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="200dip" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="mykey" 
    android:layout_alignParentBottom="true" /> 
</RelativeLayout> 

我已經以具有圓角和筆劃施加一個簡單的形狀,以的MapView:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:bottomRightRadius="10dp" 
       android:bottomLeftRadius="10dp" 
       android:topLeftRadius="10dp" 
       android:topRightRadius="10dp"/> 
    <stroke android:width="3dp" 
       android:color="@color/bordure_tables" /> 
</shape> 

我使用以下申請的形狀:

mapView.setBackgroundResource(R.layout.map); 

問題是它沒有任何效果,我看不到我的圓角,也沒有中風。

+0

有人請嗎? – 2011-05-27 08:39:26

+0

同樣的問題!請幫助我們。 – 2011-09-27 03:07:32

回答

1

你有沒有試過把它分配給一個填充?

<padding 
    android:left="2dp" 
    android:top="2dp" 
    android:right="2dp" 
    android:bottom="2dp" /> 

所以你的筆畫和半徑應該是可見的。

+0

這對mapview不起作用,它確實是一個不稱職的組件:) – Warpzit 2011-12-21 12:07:28

0

所以,我已經實現了通過做以下這個影響:我創建了一個9補丁繪製所謂round_corners並把它放在我的繪製文件夾,然後我用下面的XML繪製地圖:

<FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">/ 

     <com.google.android.maps.MapView 
      android:id="@+id/center_map" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:clickable="true" 
      android:apiKey="your_key" 
     /> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:background="@drawable/round_corners" 
     ></LinearLayout> 
    </FrameLayout> 
4

只是寫了一個教程,有一個MapView的,它的完成編程所以應該很好地擴展到所有設備圓角:

http://www.anddev.org/novice-tutorials-f8/rounded-corners-map-view-t56908.html

一旦你已經添加的自定義視圖類,你可以只是實例化一個圓形的MapView,比如s ○:

<com.blundell.tut.ui.widget.RoundedMapView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 
+0

當你完成組件時,這將是一個很好的解決方案:) – Warpzit 2011-12-21 12:08:07

0

我能夠實現這個創建圓形繪製這樣的:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
    <solid android:color="@android:color/transparent" /> 
    <stroke android:width="10dp" android:color="@color/color_gray5_eeeeee" /> 
    <corners android:radius="10px" /> 
</shape> 

然後使用線性佈局和可繪製筆劃寬度的相同尺寸的裕度,這樣的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background_gray_rectangle_rounded_corners" 
android:orientation="vertical"> 

<com.google.android.gms.maps.MapView 
    android:id="@+id/map_details_map_view" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_marginTop="10dp" 
    android:layout_marginBottom="10dp" 
    android:clickable="true" 
    android:enabled="true" /> 
</LinearLayout>