If you want to add rounded corner to any kind of android view like linear layout, relative layout, button etc., follow the below method

Method 1

Create a xml file under your drawable folder with following code. (The name of the file I created is rounded_corner.xml)

<?xml version="1.0" encoding="utf-8"?>

    <!-- view background color -->
        android:color="#a9c5ac" >

    <!-- view border color and width -->
        android:color="#1c1b20" >

    <!-- If you want to add some padding -->
        android:bottom="4dp"    >

    <!-- Here is the corner radius -->
        android:radius="10dp"   >


And keep this drawable as background for the view to which you want to keep rounded corner border. Let’s keep it for a LinearLayout

<LinearLayout android:layout_width="wrap_content"
        <TextView android:layout_width="fill_parent"
            android:text="Hi, This layout has rounded corner borders ..."

Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.

  • rubbingalcoholic

    Amazing! You are the best. Thanks.

  • Diego Lopez

    What if I want only bottom border?

  • Andrew

    Great 🙂

  • Rahul

    Thanks for the tip! It works! But I noticed that for the different screen sizes, the roundness does not stay consistent. I put the drawables in drawable-mdpi. To maintain consistency across all screen sizes do I need to modify the radius for each screen type and put those files in the respective folder, as in drawable-hdpi, drawable-xhdpi and drawable-xxhdpi ?

    • diwpro

      you can rather put the different radius values into different dimens.xml file in folders values-hdpi, values-xhdpi, etc or bettter use 9-patch

  • Manisha

    This is great. exactly what i was searching for. Thanks Ravi

  • disqus_wDOfgYAfEj

    Thank you very much man, this is a game changer for me

  • Tati

    1. If you have image inside the layout that fills parent, this won’t work.
    2. background property really was meant for something else. Not rounded corners. what if you wanted a background image?

  • thank you so much for all the great tips specially for Android Junior Developers.

  • janki.bhalani@gmail.com

    that’s code error in run

  • janealam007

    Very helpful for me.

  • Asif Hingora

    superb dear…

  • John K Njue

    Thanks for that.

  • Taha

    how can we do it programmatically ?

  • Abdul Khalik

    super well

  • Derek McAuley

    Nice post. Thanks man. 🙂

  • Tango4567

    In Android Studio This is Not Working

    • johnshumon

      its working in android studio! At least got it fine!

  • Raja RapChic

    I am not able to add any xml file as background, and every time I get the same red alert at left side of the relative “android:background=’@drawable/rounded_corner’ ” tag. help me please

  • Rahul Arvind Patil

    how to display circular image view

  • Rahul Patil

    By using this way how to display circular image frame in android

    • Raja RapChic

      define radius

    • Raja RapChic
  • csdfdsfdf

    good work

  • deathrid

    well done, thank you

  • thank you

  • Find it helpful and really really thanks to you.

  • Find it helpful and really really thanks to you for this effort .

  • Echezona Ugbana

    Your really doing a very good job Ravi

    • Thank you Ugbana;

      • Echezona Ugbana

        Please can you also put some stuff on web service implementation using Json.

  • vrinda

    Any one please help me .In my app the navigation inside the app is not working but it is working good in google browser.

  • Good tutorial =D

  • Soukaina Karzazi

    Thanks a lot !

  • safdar khan

    sir kindly any tetorial about customized android keyboard with custom emogies ,,,plz

  • Lance Dyer

    Awesome, thanks! The key is the shape item with the corners property.

  • harsh

    thanks for this tutorial…..

  • Swati Agarwal

    Hi Ravi,

    I have a query , I have to show rounded corner but as per the percentage of task completed like we have in naukri .com for profile completetion. how can i do that ?


    hello Ravi , I have a query . i need drawable file with rounded corners and with diagonal line in drawable file .is it possible?


    hello Ravi , I have a query . i need drawable file with rounded corners and with diagonal line in drawable file .is it possible?

  • Damir

    It has a bug if you have made background color transparent

  • nk

    how to set spinner border red if the dropdown selected in a invalid input