Created
April 7, 2026 08:49
-
-
Save hungtrn75/1e1df4cb09453cc2f20a94062a6a8dfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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