Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to implement rounded corners to a 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 a fragment. setting the map inside a layout and setting it background to a rounded shape didn't help me as well and this is the result:

http://i.stack.imgur.com/LJhP1.jpg

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

EDIT: @Ryan this is the new result #2:

http://i.stack.imgur.com/69D59.jpg

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:

http://i.stack.imgur.com/1Qx66.png

Well I have finally figured this out:

http://i.stack.imgur.com/bY4N5.jpg

this is what i used for the patch:

enter image description here

Thanks.

like image 310
Emil Adz Avatar asked Jan 22 '13 22:01

Emil Adz


2 Answers

I know it's an old post, but you can try using Cards like so:

<android.support.v7.widget.CardView
    android:layout_width="300dp"
    android:layout_height="350dp"
    android:layout_gravity="center_horizontal|center_vertical"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="20dp"
    app:cardCornerRadius="12dp"
    app:cardElevation="12dp">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.v7.widget.CardView>

enter image description here

like image 163
Stephen Avatar answered Oct 29 '22 23:10

Stephen


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

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>

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

rounded_background.9.png

Hope that helps,

Ryan

like image 29
Ryan Avatar answered Oct 30 '22 01:10

Ryan