How can I round specific corners of a View?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Rounding specific corners of a View on Android is usually done with a shape drawable or a GradientDrawable configured with per-corner radii. The key detail is that Android wants the radii in a fixed order, so the code is straightforward once you know which values correspond to which corners.
XML Drawable Approach
For many views, an XML background is the simplest option:
Apply it as the view background:
This is clean, reusable, and easy to preview.
Programmatic Approach
If the corners depend on runtime state, use GradientDrawable:
The radii order is:
- top-left x and y
- top-right x and y
- bottom-right x and y
- bottom-left x and y
If that order is wrong, the rounded corners appear in the wrong places.
Rounded Corners and Clipping
Setting a rounded background does not automatically clip the contents of every child view the way people often expect. If you need children or images clipped to the same shape, you may need additional clipping behavior or a shape-aware container strategy.
This is why "the background looks rounded but my image still bleeds outside" is such a common complaint.
That distinction matters most with image-heavy cards, custom containers, and Material-style surfaces. Developers often solve the background shape and then assume the view hierarchy will clip itself automatically, but Android does not always behave that way unless clipping is explicitly part of the component strategy.
In other words, visual rounding and content clipping are related but separate concerns.
Practical Selection Guide
Use XML drawables when the shape is static and part of a reusable theme. Use programmatic drawables when the corner pattern changes at runtime, such as chat bubbles, grouped list items, or cards that change shape based on position. That choice keeps the layout simple while still giving you dynamic control where it is actually needed.
It also helps performance and maintainability. Static XML shapes are easy to reuse and preview, while code-based radii make sense only when the shape genuinely depends on runtime conditions.
That tradeoff is worth making deliberately.
It usually pays off.
When XML Is Better
Choose XML when:
- the shape is static
- the style is reused in several layouts
- designers want easy preview and theming
Choose code when:
- the corner combination changes dynamically
- the color and radii depend on runtime state
- you are generating views programmatically
Common Pitfalls
- Putting the radii in the wrong order for
cornerRadii. - Expecting the background to clip all child content automatically.
- Using pixel values directly instead of density-aware dimensions.
- Rebuilding many drawable objects unnecessarily in list-heavy UIs.
- Solving a static design problem in code when an XML drawable would be simpler.
Summary
- Specific Android view corners can be rounded with XML drawables or
GradientDrawable. - '
cornerRadiiuses a fixed top-left to bottom-left ordering.' - XML is best for reusable static styling.
- Runtime code is best for dynamic corner combinations.
- Rounded backgrounds and clipped child content are related but not identical problems.

