如何显示android mapfragment视图的圆形形状

时间:2013-11-29 05:03:23

标签: android google-maps android-mapview android-ui supportmapfragment

我必须以圆角形状显示地图视图,是否可以显示圆形的android地图视图。 我试图应用片段布局gadient但在地图加载后显示rectange视图。 任何使android圆形mapview的指南

2 个答案:

答案 0 :(得分:1)

是的,有可能。用另一个布局覆盖MapFragment,并为此布局设置一个 9-patch 背景,它将以您想要的方式覆盖它,看看我在同一主题上提出的这个问题不久前:

Is there a way to implement rounded corners to a Mapfragment?

答案 1 :(得分:0)

您可以在图层列表中使用形状 enter image description here 这是shape_circle.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/shape_circle_rect"/>
    <item android:drawable="@drawable/shape_circle_oval"/>
</layer-list>

shape_circle_rect.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    <solid android:color="@android:color/transparent"/>
    <stroke android:width="50dp" android:color="#ffffff"/>
    <padding
            android:left="-50dp"
            android:top="-50dp"
            android:right="-50dp"
            android:bottom="-50dp"/>
</shape>

shape_circle_oval.xml

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

和自定义地图片段

    public class MapFragment extends SupportMapFragment{
    //...
    //Some methods, set up map and etc.
    //...
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
        View mapView = super.onCreateView(inflater, viewGroup, bundle);
        RelativeLayout view = new RelativeLayout(getActivity());
        view.addView(mapView, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
        FrameLayout frameLayout=new FrameLayout(getActivity());
        frameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        frameLayout.setBackgroundResource(R.drawable.shape_circle);
        view.addView(frameLayout);
        return view;
    }
    //...
    //...
 }