Search code examples
javaandroidxmlimageviewrounded-corners

ImageView rounded corners


I wanted image to have rounded corners. I implement this xml code and use this in my image view. but image overlap the shape. I am downloading the image through async task.

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >
 <corners android:radius="20dip" />
</shape>


<ImageView
    android:id="@+id/trVouchersImage"
    android:layout_width="55dp"
    android:layout_height="55dp"
    android:layout_marginLeft="8dp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:layout_alignParentLeft="true"
    android:background="@drawable/ash_arrow"
 />

Solution

  • I use Universal Image loader library to download and round the corners of image, and it worked for me.

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(thisContext)
                // You can pass your own memory cache implementation
               .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
               .build();
    
    DisplayImageOptions options = new DisplayImageOptions.Builder()
                .displayer(new RoundedBitmapDisplayer(10)) //rounded corner bitmap
                .cacheInMemory(true)
                .cacheOnDisc(true)
                .build();
    
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);
    imageLoader.displayImage(image_url,image_view, options );