Issue #382

import android.content.Context

fun Int.toDp(context: Context?): Int {
    if (context != null) {
        val scale = context.resources.displayMetrics.density
        return (this.toFloat() * scale + 0.5f).toInt()
    } else {
        return 0
    }
}
val set = ConstraintSet()
set.setMargin(imageView.id, ConstraintSet.RIGHT, rightMargin.toDp(150))

Read more