0

I want to know how to make the edges of a view to be rounded, not just setting the background image with a rounded corner rectangle. Everywhere I looked, I could only find information creating the rounded corner BG image.

Specifically, I have a Google Maps fragment inside a RelativeLayout, and I want Google Maps to have rounded edges:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="120dp"
            android:id="@+id/puInfoGoogleMapLayout"
            android:animateLayoutChanges="true">

            <fragment xmlns:android="http://schemas.android.com/apk/res/android"
                android:name="com.google.android.gms.maps.MapFragment"
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </RelativeLayout>

Obviously, setting a rounded corner BG image wouldn't work. On iOS, I could do it by setting view.layer.cornerRadius = 10 and view.layer.masksToBound = YES. How do I do it in Android?

Justin Leo
  • 1,975
  • 3
  • 15
  • 14
  • make a custom parent contaner (a class extending `ViewGroup`) and override its `dispatchDraw` method – pskink Aug 26 '15 at 06:13
  • check this session http://stackoverflow.com/questions/16161448/how-to-make-layout-with-rounded-corners – RichFounders Aug 26 '15 at 06:50
  • pskink do you have any additional details? What do I do after overriding the dispatchDraw? I think that's what I need Chairizky: thanks for the suggestion, but that was not what I was looking for because Google Maps itself would not be rounded, only the background – Justin Leo Aug 27 '15 at 19:01

2 Answers2

1

use cardview and put your relativelayout inside it....

challenger
  • 2,184
  • 1
  • 18
  • 25
0

Create a Shape xml in your drawable folder .and set it as background of your view ..Like this . `

 <?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="1dp"
     android:color="@android:color/transparent"/>
     <corners android:radius="15dip"/>
 </shape>

Then You need to set it as background of your view in your xml

android:background="@drawable/yourshapexmlname"
ADM
  • 20,406
  • 11
  • 52
  • 83
  • thanks for the answer, but this is not what I was looking for because Google Maps itself would not be rounded, only the background. I need the contents INSIDE the relative layout to be rounded as well. – Justin Leo Aug 27 '15 at 19:01