百度地图MapView实现圆角

效果图


在百度和百度地图社区都找不到什么资料,查了好久的百度api也看不到什么方法,后来自己想歪办法实现了,在这里记录一下,也可以帮助到有需要的人

我目前使用的百度地图版本是4.0,在官方提供的api的MapView和BaiduMap都找不到什么设置圆角的方法(找到的请不要喷我)

实现方式,在MapView下面再使用一个View,背景是一个shape,中间透明,框距和圆角的边框一样,框的颜色和背景颜色一样

再在这个View下面使用一个View,这个是圆角的View,这样就实现了MapView圆角.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
                android:background="#f0f0f0"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
        android:background="#f00"
        android:textColor="@android:color/black"
        android:text="这是MapView"
        android:textSize="20dp"
        android:gravity="center"
        android:layout_margin="20dp"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>
    <View
        android:background="@drawable/map_bg1"
        android:layout_margin="20dp"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>
    <View
        android:background="@drawable/map_bg2"
        android:layout_margin="20dp"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>
</RelativeLayout>
map_bg1

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent"/>
    <stroke android:color="#f0f0f0" android:width="10dp"/>
</shape>
map_bg2

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent"/>
    <stroke android:color="#eaeaea" android:width="10dp"/>
    <corners android:radius="25dp"/>
</shape>
效果

扫描二维码关注公众号,回复: 2393146 查看本文章

不过这样做还有一个问题,百度地图的logo和比例尺一部分被遮住了,所以看起来怪怪我,所以我直接把百度地图的logo和比例尺去掉

View child = mMapView.getChildAt(1);
if (child != null && (child instanceof ImageView || child instanceof ZoomControls)){            
     child.setVisibility(View.INVISIBLE);           
}
        
//地图上比例尺        
mMapView.showScaleControl(false);




猜你喜欢

转载自blog.csdn.net/android_upl/article/details/76599081
今日推荐