Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView scaleType="fitXY" is not working in pre-lollipop device inside the Cardview | Android

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.
Image 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>
like image 859
Ravindra Kushwaha Avatar asked Mar 07 '17 09:03

Ravindra Kushwaha


1 Answers

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..

like image 179
Keivan Esbati Avatar answered Nov 11 '22 17:11

Keivan Esbati