Kotlin - rounded corners on image
From zen2
Image
To create rounded corners for existing image, programatically:
val bitmap = BitmapFactory.decodeResource(resources,R.drawable.devslopesprofilelogo) val roundedLogo = RoundedBitmapDrawableFactory.create(resources,bitmap) roundedLogo.cornerRadius = 15f logo.setImageDrawable(roundedLogo)
Circular images
For fully circular:
val bitmap = BitmapFactory.decodeResource(resources,R.drawable.devslopesprofilelogo) val roundedLogo = RoundedBitmapDrawableFactory.create(resources,bitmap) roundedLogo.isCircular = true logo.setImageDrawable(roundedLogo)
Widget
To create rounded corners for a button:
- Drawable in tree|New|Drawable Resource File
- Give it a name such as rounded_gradient, click ok etc
- Open the rounded_gradient.xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp"/>
<gradient
android:startColor="#80df4326"
android:endColor="#DF4326"
android:angle="45"
/>
</shape>
Navigate back to the design view, choose the button, and as background select the drawable rounded_gradient you just created
