【问题标题】:how to display android mapfragment view rounded shape如何显示android mapfragment视图圆形
【发布时间】:2013-11-29 05:03:22
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您可以在图层列表中使用形状 这里是 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;
        }
        //...
        //...
     }
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2021-03-17
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多