Is Every ImageView Need CardView?

Viewed 39

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..

2 Answers

If you are using Glide V4

Try like this

Glide.with(this.context)
                .load(url)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(14)))
                .into(ImageView);

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

Related