Round corners on an Android ImageView

1. Create a new Android project in Eclipse or Android Studio.

2. In the /res/drawable folder, create a frame.xml file. In it, we define a simple rectangle with rounded corners and a transparent center.

frame.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
     <solid android:color="#00ffffff" />
     <padding android:left="6dp"
        android:top="6dp"
        android:right="6dp"
        android:bottom="6dp" />
     <corners android:radius="12dp" />
     <stroke android:width="6dp" android:color="#ffffffff" />
</shape> 

3. In the /res/drawable-xhdpi folder include the image you wish to use as the source for your ImageView.

4. In the /res/layout folder modify activity_main.xml. In it, you will see a LinearLayout that contains a standard ImageView, as well as a nested FrameLayout. The FrameLayout uses padding and the custom drawable to give the illusion of rounded corners.

activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="center"
    android:gravity="center" 
    android:background="#ffffffff">

    <ImageView
        android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:padding="6dp"
        android:src="@drawable/tr"/>
    
    <FrameLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        
        <ImageView
            android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:padding="6dp"
	        android:src="@drawable/tr"/>
        
        <ImageView 
	         android:src="@drawable/frame"
	         android:layout_width="match_parent"
	         android:layout_height="match_parent" />
        
    </FrameLayout>

</LinearLayout>
  • Salomon

    Hello, I would like to subscribe for this website to get newest updates, thus where can i do it please assist.

  • timberland

    Iˇve recently started a site, the information you offer on this website has helped me tremendously. Thanks for all of your time & work.

  • James

    Highly informative blog, I loved it a lot. thanks

  • Sohali

    Hi everybody, here every one is sharing these kinds of familiarity, thus it’s
    fastidious to read this website, and I used to visit this blog every day.

  • Neha

    Hello very cool website!! Guy .. Beautiful .. Superb .. I’ll bookmark your blog and take the feeds alsoI am glad to seek out a lot of useful information right here within the submit, we’d like develop extra strategies on this regard, thanks for sharing. . . . . .

  • Ashish

    I am always browsing online for posts that can facilitate me. Thx!

  • pevdsa

    Very nice post and straight to the point. I am not sure if this is really the best place to ask but do you people have any ideea where to employ some professional writers? Thx 🙂