本文介绍了有没有办法为 Mapfragment 实现圆角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给地图一个漂亮的圆角,就像它下面的两个框一样.我不能用它自己的地图片段来做,因为没有背景属性分段.在布局内设置地图并将其背景设置为圆形对我没有帮助同样,这是结果:

I want to give the map a nice looking rounded corners as the two boxes below it have.I can't do it with the map fragment it self because there is not a background property to afragment.setting the map inside a layout and setting it background to a rounded shape didn't help meas well and this is the result:

我可以合并地图,但这会使它变小,我想避免它.

I could merge the map but this would make it smaller and i would like to avoid it.

@Ryan 这是新结果 #2:

@Ryan this is the new result #2:

我想这还不错,甚至没有靠近其他盒子的角落,但仍然不错,多做一点工作可以接近某个地方,我只是没有普通的图像编辑器.但现在仍然困扰我的一件事是位置"文本视图和它自己的地图之间的分离.我可以用其他方式画补丁以便现在有距离吗?我就是这样做的:

I guess this is not bad, no even close to the corners on the other boxes,but still not bad with a little more work a could get somewhere close i just dont have a normal image editor.but one thing that still bothers me now is the separation between the "Location" Textview and the map it's self. could i painted the patch in other way so that there was now distance? this is how i did it:

好吧,我终于想通了:

这是我用于补丁的内容:

this is what i used for the patch:

谢谢.

推荐答案

我还没有尝试过这个,但我会在 mapView/mapFragment 顶部放置一个带有圆角和透明中间的视图.

I haven't tried this, but I'd put a view with rounded corners and a transparent middle on top of the mapView / mapFragment.

即把mapFragment和圆角视图放在一个FrameLayout中,都填充FrameLayout,然后让圆角视图中间透明.

That is, put the mapFragment and the rounded corner view in a FrameLayout with both filling the FrameLayout, then make the middle of the rounded corner view transparent.

为了进一步说明,您可以按如下布局进行操作:-

For further clarification, you could do it in a layout as follows:-

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/rounded_background"
    android:orientation="vertical" >
</LinearLayout>

</FrameLayout>

rounded_background 是一个带有圆角和透明中间的 9-patch.例如

The rounded_background is a 9-patch with rounded corners and a transparent middle. E.g.

希望有所帮助,

瑞恩

这篇关于有没有办法为 Mapfragment 实现圆角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:38