我是靠谱客的博主 懦弱铅笔,这篇文章主要介绍百度地图MapView实现圆角,现在分享给大家,希望可以做个参考。

效果图


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

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

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

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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

复制代码
1
2
3
4
5
<?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

复制代码
1
2
3
4
5
6
<?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>
效果

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

复制代码
1
2
3
4
5
6
7
View child = mMapView.getChildAt(1); if (child != null && (child instanceof ImageView || child instanceof ZoomControls)){ child.setVisibility(View.INVISIBLE); } //地图上比例尺 mMapView.showScaleControl(false);




最后

以上就是懦弱铅笔最近收集整理的关于百度地图MapView实现圆角的全部内容,更多相关百度地图MapView实现圆角内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(86)

评论列表共有 0 条评论

立即
投稿
返回
顶部