문제

i have to show map view in rounded shape , is it posible to show android map view with rounded shape. I have tried to applying fragment layout gadient but after map loading is showing rectange view. any guidence for to make android rounded mapview

도움이 되었습니까?

해결책

Yes, it possible. Cover the MapFragment with another layout, and set for this layout a 9-patch background, that will cover it the way you want, take a look at this question I asked on the same topic not long ago:

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

다른 팁

You can use shapes in layer-list enter image description here here is the 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>

and Custom Map Fragment

    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;
    }
    //...
    //...
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top