将圆角添加到mapview

问题描述 投票:3回答:5

我正在尝试编写一个简单的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);

问题是它没有任何效果,我看不到圆角,也看不到笔画。

android android-mapview rounded-corners
5个回答
3
投票

刚刚编写了一个教程,在MapView上有圆角,它以编程方式完成,所以应该可以很好地扩展到所有设备:

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

添加自定义视图类后,您可以像这样实例化一个舍入的mapview:

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

1
投票

你试过给它填充一个填充物吗?

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

所以你的笔画和半径应该是可见的。


0
投票

所以我通过以下方式实现了这种效果:我创建了一个名为round_corners的9-patch drawable并将其放置在我的drawable文件夹中,然后我使用以下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>

0
投票

我能够实现这个创建一个圆形的drawable像这样:

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

0
投票

只需将Mapview放入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>
© www.soinside.com 2019 - 2024. All rights reserved.