I wanted image to have rounded corners. I implement this xml code and use this in my image view. but image overlap the shape. I am downloading the image through async task.<
Now we no need to use any third party lib or custom imageView
SAMPLE CODE
First add below
dependenciesin yourbuild.gradlefile
implementation 'com.google.android.material:material:1.2.0-alpha05'
Add ShapeableImageView in your layout
Kotlin code to make ImageView Circle
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.android.material.shape.CornerFamily
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 50dp
val radius = resources.getDimension(R.dimen.image_corner_radius)
myShapeableImageView.shapeAppearanceModel = myShapeableImageView.shapeAppearanceModel
.toBuilder()
.setTopRightCorner(CornerFamily.ROUNDED, radius)
.setTopLeftCorner(CornerFamily.ROUNDED, radius)
.setBottomLeftCorner(CornerFamily.ROUNDED, radius)
.setBottomRightCorner(CornerFamily.ROUNDED, radius)
.build()
// or You can use setAllCorners() method
myShapeableImageView.shapeAppearanceModel = myShapeableImageView.shapeAppearanceModel
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED, radius)
.build()
}
}
OUTPUT
First, create a below style in your style.xml
Now use that style in your layout like this
OUTPUT
Please find the complete exmaple here how to use ShapeableImageView