Adding rounded corners to a mapview

前端 未结 5 1496
迷失自我
迷失自我 2020-12-10 09:31

I\'m trying to code a simple MapActivity which uses the following layout (only contains the mapview for the moment, as I plan to add share the screen with a ListView in the

相关标签:
5条回答
  • 2020-12-10 10:02

    Just wrote a tutorial to have rounded corners on a MapView it's done programmatically so should scale well to all devices:

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

    Once you have added the custom view class you can just instantiate a rounded mapview like so:

    <com.blundell.tut.ui.widget.RoundedMapView
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"/>
    
    0 讨论(0)
  • 2020-12-10 10:09

    Just put the Mapview into a CardView

     <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:elevation="0dp"
            app:cardCornerRadius="5dp">
    
         <com.google.android.gms.maps.MapView
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    
     </android.support.v7.widget.CardView>
    
    0 讨论(0)
  • So I've achieved this affect by doing following: I've created a 9-patch drawable called round_corners and placed it in my drawable folder, then I use following xml to plot the map:

        <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>
    
    0 讨论(0)
  • 2020-12-10 10:17

    I was able to achieve this creating a rounded drawable like this:

    <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>
    

    then using a linear layout and a margin of the same size of the drawable stroke width, like this:

    <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>
    
    0 讨论(0)
  • 2020-12-10 10:18

    Have you tried assigning it a padding?

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

    So your strokes and radius should be visible.

    0 讨论(0)
提交回复
热议问题