[ShapeableImageView] Rounded corners stroke is cut-off by default
See original GitHub issueDescription:
By default, when a ShapeableImageView
has rounded corners and you define strokeWidth
and strokeColor
, it will be cut-off.
In the screenshot just below, you can see it compared to TextInputLayout
below it, which renders fine.
Expected behavior:
Rendering to not appear cut-off by default, without having to increase the padding
.
Source code: Extension:
fun ShapeableImageView.roundAllCorners(@Dimension radius: Float) {
shapeAppearanceModel = shapeAppearanceModel.toBuilder()
.setAllCorners(CornerFamily.ROUNDED, radius)
.build()
}
Code:
myImageView.apply {
roundAllCorners(dp(8f))
strokeColor = colorSL(R.color.image_border_on_background)
strokeWidth = dp(2) // Happens with bigger values as well.
//padding = strokeWidth // Uncommenting this fixes rendering.
adjustViewBounds = true
}
The dp
extensions come from Splitties.
Android API version: 29
Material Library version: 1.2.0-alpha06
Device: Google Pixel 2 XL
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:9 (5 by maintainers)
Top Results From Across the Web
ShapeableImageView's stroke is getting cut by borders
I think it is supposed to just clip its image resource to the specified shape. <com.google.android.material.imageview.ShapeableImageView android ...
Read more >Deep Dive Into ShapeableImageView in Android - ITNEXT
As before will use the same style we created for the rounded corner Image and will add strokeWidth, and strokeColor to the ShapeableImageView....
Read more >ShapeableImageView - Android Developers
Gets the stroke width for this ImageView. void, setContentPadding(int left, int top, int right, int bottom). Set additional padding on the image ...
Read more >Cardview Is Cut At The Sides - ADocLib
[ShapeableImageView] Rounded corners stroke is cutoff by default #1329 of the same width as the stroke would push the borders so the image...
Read more >ShapeableImageView – Material components for android
For the corner cut imageview, we are going to use cornerFamily . by default, cornerFamily will be rounded. In our case, we need...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Setting the padding, and adjusting the shape dimensions WTR to the padding, worked for me.
ShapeAppearance
This allowed my image to be drawn without the box clipping effect
There seems like no general solutions for all possible cases.
I’ll close this as infeasible for now. Please feel free to reopen it or create a PR if you have a good idea to solve this.