Material-components-android: ImageView inside MaterialCardView fit width and height with shape corners

Created on 1 Mar 2019  路  10Comments  路  Source: material-components/material-components-android

Hello. I want to place an ImageView inside a card.
And the card have a shapeAppearance with a different rounded corners.
I set cardPreventCornerOverlap = false to make the image fit the card dimensions but I want that image be cut at the corners as well.
How can I do that?

image

Most helpful comment

A workaround while we still try to figure out the best way to solve this
googlesamples/android-sunflower#437

All 10 comments

Hello! We were recently talking about creating something like a ShapeableImageView to support this case.

@dsn5ft That would be great! Is it something I can do to cut the image? Or it is not possible until we get a new ShapeableImageView?

I believe we will be using the outline provider apis so you could try experimenting with that if you're interested.

@dsn5ft Well I had a look into the Ouline API and could not find a way to provide different radius for every corner.
I understand the idea with a new ShapeableImageView but what about background? For example, if I provide an image background for a direct child of a card view it does not respect the card view bounds and shape.
So right now I do not see a simple way to get the card view with a full-width background image like in Material Spec examples.
https://material.io/design/components/cards.html#behavior

The ShapeableImageView would match the shape of the card's corners, so we wouldn't have to actually update the bounds of the image view. I think it would let you achieve what's in the spec.

I wonder if ShapeableImageView concept is somehow compatible with image loaders like Fresco - and I fear it's not :(

@hrach if We have an ImageView you could use Fresco to load the bitmap and just set the bitmap in the ImageView. What would you expect instead?

Well, Fresco is mostly powerful when the image is drawn by their own SimpleDraweeView (fallback image, placeholder image, cropping and ratio-sizes, ...). Actually I have no idea how exactly the corner treatment internally works and if they could somehow support this out of the box. Fetching a bitmap is definitely somehow possible, though, probably by using Picasso, where this is much more friendly to the usecase.

Fetching a bit map is definitely friendly to the usecase

A workaround while we still try to figure out the best way to solve this
googlesamples/android-sunflower#437

Was this page helpful?
0 / 5 - 0 ratings