Actions

Kotlin - rounded corners on image

From zen2

Revision as of 21:10, 22 November 2017 by Chris (talk | contribs)

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"
    />
</shape>