how to remove empty spaces of imageview without cropping them

I’m trying to add a ImageView to my CardView but i don’t know how to set image inside of ImageView that has a Full Width (match_parent) and a wrap_content height ! By default there would be some spaces in Imageview (bottom and top parts, depend on width and height of image) as you see below :

how does instagram fill it's images without cropping them?

any way to remove these empty spaces without cropping images ?

here is my layout :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardElevation="3dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/cardviewLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/ryan_gosling"
            />
    </LinearLayout>

</RelativeLayout>
</android.support.v7.widget.CardView>

Answer

Ok the Problem is Solved.
A really simple code :

android:adjustViewBounds="true"

Leave a Reply

Your email address will not be published. Required fields are marked *