2019-08-28a few seconds read (About 63 words)How to use point in dp programmatically in AndroidIssue #382 12345678910import android.content.Contextfun Int.toDp(context: Context?): Int { if (context != null) { val scale = context.resources.displayMetrics.density return (this.toFloat() * scale + 0.5f).toInt() } else { return 0 }} 12val set = ConstraintSet()set.setMargin(imageView.id, ConstraintSet.RIGHT, rightMargin.toDp(150)) Read more https://stackoverflow.com/questions/5255184/android-and-setting-width-and-height-programmatically-in-dp-units #androidkotlin