2

I am using imageView for upload profile image but i got a issue about it..

    <ImageView
        android:id="@+id/profile_image"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:background="@drawable/roundimage"
        android:src="@drawable/profile_pic"
        android:scaleType="centerCrop"
        android:layout_centerHorizontal="true" />

I set a round corner background and set source a image icon so when i select pic from gallery then my selected pic does not have round corner. I mean its looks like square image instead of round corner image..

  • 1
    If you want to do it without the `CardView`, then you need to implement a Custom ImageView. Refer to https://stackoverflow.com/questions/2459916/how-to-make-an-imageview-with-rounded-corners for more details. – Abhishek Jul 02 '19 at 17:27
  • 1
    That's not how src and background work. The src image isn't clipped to the background. The background is drawn (ignoring scale type), then the src is drawn on top of it. The native image view doesn't do what you want. There's a variety of 3rd party libraries that do. – Gabe Sechan Jul 02 '19 at 17:27

2 Answers2

1

If you are using Glide V4

Try like this

Glide.with(this.context)
                .load(url)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(14)))
                .into(ImageView);
Nizamudeen Sherif
  • 1,002
  • 1
  • 12
  • 38
0

No need. There are several Libraries such as

1. CircleImageView

2. RoundedImageView

You can use CircleImageView as below

    dependencies {
    ...
    implementation 'de.hdodenhof:circleimageview:3.0.0'
}

Inside the layout

<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_image"
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:src="@drawable/profile"
    app:civ_border_width="2dp"
    app:civ_border_color="#FF000000"/>

You can use RoundedImageView as below

    repositories {
    mavenCentral()
}

dependencies {
    compile 'com.makeramen:roundedimageview:2.3.0'
}

Inside the layout

 <com.makeramen.roundedimageview.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="fitCenter"
        app:riv_corner_radius="30dip"
        app:riv_border_width="2dip"
        app:riv_border_color="#333333"
        app:riv_mutate_background="true"
        app:riv_tile_mode="repeat"
        app:riv_oval="true" />

for more information please visit the following sites CircleImageView

RoundedImageView

Udara Abeythilake
  • 1,215
  • 1
  • 20
  • 31