Skip to content

Instantly share code, notes, and snippets.

@hungtrn75
Created April 7, 2026 08:49
Show Gist options
  • Select an option

  • Save hungtrn75/1e1df4cb09453cc2f20a94062a6a8dfb to your computer and use it in GitHub Desktop.

Select an option

Save hungtrn75/1e1df4cb09453cc2f20a94062a6a8dfb to your computer and use it in GitHub Desktop.
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline?) {
if (view.width <= 0 || view.height <= 0 || outline == null) return
if (tlPx == trPx && trPx == brPx && brPx == blPx) {
outline.setRoundRect(0, 0, view.width, view.height, tlPx)
return
}
val path = android.graphics.Path()
val radii = floatArrayOf(
tlPx, tlPx,
trPx, trPx,
brPx, brPx,
blPx, blPx
)
val rectF = android.graphics.RectF(0f, 0f, view.width.toFloat(), view.height.toFloat())
path.addRoundRect(rectF, radii, android.graphics.Path.Direction.CW)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
outline.setPath(path)
} else {
@Suppress("DEPRECATION")
outline.setConvexPath(path)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment