I have ImageView
which is inside the CardView
as below in my code. My ImageView
scaleType="fitXY" is not working on pre-lollipop devices.But it looks better on Lollipop devices. Please look at below images.
As we see in above image there is white padding around the imageview which i want to remove, I want to look alike image on both pre-lolipop and post lolipop devices. Please help me to short out from the problem. Thanks :)
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginRight="10dp"
android:layout_marginTop="6dp"
app:cardCornerRadius="10dp"
card_view:cardUseCompatPadding="false"
>
<ImageView
android:id="@+id/imgChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>
This Gap is Result of CardView
internal padding in Pre-lollipop device. Since in Api < 21 there is no native support for Shadows and Clipping CardView
recreate these effects through fallback solutions.
Now if you define a cardCornerRadius
, in Pre-lollipop devices the CardView
will apply content padding (Equal to corner radius value) to your content in order to prevent your content overlapping Corners.
To disable this behavior, You can do this in XML:
card_view:cardPreventCornerOverlap="false"
or using java:
cardView.setPreventCornerOverlap(false)
to disable overlap corner padding.
Update: If you really want to achieve the same effect in pre-lollipop device you can try to clip your image yourself using libraries like this one:
https://github.com/vinc3m1/RoundedImageView
, So when your content overlap CardView
the Corners gonna overlap and you will get the same look as post-lollipop devices..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With