-1

Is there any way to round the corners of an ImageView through xml layout? And even if not, what are the ways we can achieve that?

PS: The image urls are being fetched from an API. Not from drawable folder

  • 2
    try sample from this link: [https://stackoverflow.com/questions/20743859/imageview-rounded-corners](https://stackoverflow.com/questions/20743859/imageview-rounded-corners) –  May 29 '19 at 05:56
  • 1
    Possible duplicate of [ImageView rounded corners](https://stackoverflow.com/questions/20743859/imageview-rounded-corners) – Basi May 29 '19 at 05:58

3 Answers3

1

by using Glide library

use

Glide
  .with(context)
  .load(url)
  .apply(
      RequestOptions()
        .circleCrop())
  .into(imageView)
Basi
  • 3,009
  • 23
  • 28
0

You can achieve it using custom views like this

public class RoundImageView extends ImageView {

    private float mRadius = 18.0f;
    private Path mPath;
    private RectF mRect;

    public RoundImageView(Context context) {
        super(context);
        init();
    }

    public RoundImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        mPath = new Path();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        mRect = new RectF(0, 0, this.getWidth(), this.getHeight());

        mPath.addRoundRect(mRect, mRadius, mRadius, Path.Direction.CW);

        canvas.clipPath(mPath);

        super.onDraw(canvas);
    }
}

and use it in your XML

<your_pkag.RoundImageView
     android:id="@+id/imgView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:src="@drawable/image" />
Basi
  • 3,009
  • 23
  • 28
0

I don't know what you want to make. But for the borders.

You can create a drawable file like below.

line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="5dp" />
    <stroke android:width="2dp" android:color="#000" />
</shape>

activity_xxx.xml

    <ImageView
        android:layout_height:"200dp"
        android:layout_width:"200dp"
        android:background:"@drawable/line.xml"
    />
c-an
  • 3,543
  • 5
  • 35
  • 82