0

In my application I need ImageView with rounded corners, So I have set ImageView inside framelayout, When I set the scaleType centerCrop, the image set inside the ImageView is stretching in first loading and, again refreshing the page the image is not stretching and set with round corners.How can I avoid the first stretching.Thanks in advance
Here is the XML code

<FrameLayout
    android:id="@+id/imageframe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/dp_80"
        android:layout_height="@dimen/dp_80"
        android:background="@drawable/image_rounded"
        android:src="@drawable/dummypost1"
        android:scaleType="centerCrop"/>

    <ImageView
        android:src="@drawable/image_rounded"
        android:layout_width="@dimen/dp_80"
        android:layout_height="@dimen/dp_80"
        android:scaleType="centerCrop"/>

</FrameLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    For rounded corner, you can take a look in this https://stackoverflow.com/questions/2459916/how-to-make-an-imageview-with-rounded-corners – Hinte Mar 16 '18 at 09:50

1 Answers1

2

If you want an ImageView with rounded corners, there is no need for wrapping like this.

you can use only ImageView in your layout and using glide, you can apply round corners using this method.

first in your gradle write,

compile 'com.github.bumptech.glide:glide:3.7.0'

for image with rounded corners,

public void loadImageWithCorners(String url, ImageView view) {
    Glide.with(context)
            .load(url)
            .asBitmap()
            .centerCrop()
            .placeholder(R.color.gray)
            .error(R.color.gray)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(new BitmapImageViewTarget(view) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCornerRadius(32.0f); // radius for corners
                    view.setImageDrawable(circularBitmapDrawable);
                }
            });
}

call method :

loadImageWithCorners("your url","your imageview");
Deep Patel
  • 2,584
  • 2
  • 15
  • 28