Last active
January 21, 2020 18:00
-
-
Save robsenshuu/8751db8eafafc593eb08544a837c3705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.graphics.drawable.BitmapDrawable | |
import android.graphics.drawable.Drawable | |
import android.util.AttributeSet | |
import android.widget.ImageView | |
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory | |
class CircularImageView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyle: Int = 0 | |
) : ImageView(context, attrs, defStyle) | |
override fun setImageDrawable(drawable: Drawable?) { | |
val radius = 100f | |
val bitmap = (drawable as BitmapDrawable).bitmap | |
val rid = RoundedBitmapDrawableFactory.create(resources, bitmap) | |
rid.cornerRadius = bitmap.width * radius | |
super.setImageDrawable(rid) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment