向地图视图添加圆角
我正在尝试编写一个简单的 MapActivity,它使用以下布局(目前仅包含地图视图,因为我计划将来添加与 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>
我已按顺序将简单的形状应用于地图视图具有圆角和描边:
<?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);
问题是它没有任何效果,我看不到我的圆角,也看不到描边。
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 future) :
<?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>
I have applied a simple shape to the mapview in order to have round corners and a stroke :
<?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>
I use the following to apply the shape :
mapView.setBackgroundResource(R.layout.map);
Problem is that it does not have any effect and I can't see my rounded corners, nor the stroke.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
刚刚写了一个教程,在 MapView 上设置圆角,它是通过编程完成的,因此应该可以很好地扩展到所有设备:
http://www.anddev.org/novice-tutorials-f8/rounded-corners-map-view-t56908.html
添加自定义视图类后您可以像这样实例化一个圆形地图视图:
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:
您是否尝试过为其分配填充?
所以你的笔画和半径应该是可见的。
Have you tried assigning it a padding?
So your strokes and radius should be visible.
因此,我通过执行以下操作实现了这种效果:我创建了一个名为 round_corners 的 9 补丁可绘制对象并将其放置在我的可绘制文件夹中,然后使用以下 xml 来绘制地图:
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:
我能够实现这一点,创建一个圆形可绘制对象,如下所示:
然后使用线性布局和与可绘制笔划宽度相同大小的边距,如下所示:
I was able to achieve this creating a rounded drawable like this:
then using a linear layout and a margin of the same size of the drawable stroke width, like this:
只需将Mapview放入CardView即可
Just put the Mapview into a CardView