1

我必须以圆形显示地图视图,是否可以以圆形显示 android 地图视图。我曾尝试应用片段布局 gadient,但地图加载后显示矩形视图。制作 android rounded mapview 的任何指南

4

2 回答 2

1

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

有没有办法为 Mapfragment 实现圆角?

于 2013-11-29T06:31:45.443 回答
0

您可以在图层列表中使用形状, 在此处输入图像描述 这里是 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;
    }
    //...
    //...
 }
于 2013-11-29T07:07:40.967 回答