Shudy February 2016

Glide Android - Doesn't show all the image

I have to take a picture in my App. After take it , I have to show it in a ImageView, so I decided to use Glide as library to handle it.

I have set the code like this:

Glide.with(this)
                .load(mLastPhoto)
                .fitCenter()
                .centerCrop()
                .into(iv_circ_image);

and the xml file looks like:

<ImageView
                android:id="@+id/circ_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bTakePicture"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="12dp"
                android:src="@drawable/ab_background_textured_" />

But when the phot has been taken, the image is shown like this:

enter image description here

How I have to set the Glide code or the XML to show all the image?

Answers


Christopher February 2016

Add the android:adjustViewBounds="true" attribute to your ImageView. Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable (from API-Documentation http://developer.android.com/reference/android/widget/ImageView.html).

<ImageView
    android:adjustViewBounds="true"
    android:id="@+id/circ_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/bTakePicture"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="12dp"
    android:src="@drawable/ab_background_textured_" />


Shmuel February 2016

In the xml you have android:layout_height="wrap_content" and android:layout_marginTop="12dp"

Then in the java you have .fitCenter().centerCrop().

So basically you have a 12dp image view that Glide is filling. I suggest you set the height of the image view (ie 200dp) or have the buttons stick to the bottom of the screen and have the imageview fill the available space between them.

Post Status

Asked in February 2016
Viewed 2,048 times
Voted 4
Answered 2 times

Search




Leave an answer