Make ImageView fit width of CardView
EDIT 2015/09/29
https://github.com/vinc3m1/RoundedImageView added support of rounding of selected corners
You can also use makeramen RoundedImageView https://github.com/vinc3m1/RoundedImageView, and to remove auto padding in CardView for pre LolliPop use
yourCardView.setPreventCornerOverlap(false);
And then set padding you needded to show shadows of cardview
I got this to work by putting a RoundedImageView
inside of a CardView
. Also you need to set the appropriate CardView
attributes.
https://medium.com/@etiennelawlor/layout-tips-for-pre-and-post-lollipop-bcb2e4cdd6b2#.kmb24wtkk
You need to do 2 things :
1) Call setPreventCornerOverlap(false)
on your CardView.
2) Put rounded Imageview inside CardView
About rounding your imageview, I had the same problem so I made a library that you can set different radii on each corners. There is one good library(vinc3m1’s RoundedImageView) that supports rounded corners on ImageView, but it only supports the same radii on every corners. But I wanted it to be rounded only top left and top right corners.
Finally I got the result what I wanted like below.
https://github.com/pungrue26/SelectableRoundedImageView
If your image size (width) is fixed with your ImageView
width, you just only have to do is change your ImageView
attribute to :
android:scaleType="fitXY"
That is. No additional image corner rounding, no busy work. Beside it efficient for app's performance.
Note : my suggestion may not appropriate for small image with large size ImageView
.