I have the following ImageView
in my XML layout:
<ImageView
android:id="@+id/image_attachement"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginBottom="12dp"
android:background="@drawable/rounded_rectangle"
android:contentDescription="@string/imageattachment"
android:onClick="@{()-> viewModel.openGalleryOrImageCameraEvent()}"
android:padding="@dimen/spacing_large"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sendButton"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/audio_attachement"
app:srcCompat="@drawable/ic_photo_camera_black_24dp" />
Here is an image how the ImageView
looks like:
Now, when the user selects an image from camera or the gallery, I want to show the thumbnail of that selected image inside this imageview. Here is my Glide code to achieve that:
val requestOptions = RequestOptions()
.placeholder(R.drawable.white_background)
.error(R.drawable.white_background)
val requestManager =
Glide
.with(context.applicationContext).setDefaultRequestOptions(requestOptions)
.load(uri).apply(RequestOptions.centerCropTransform()).into(bindingGroupContainer.imageAttachement)
The result is this:
As you can see, the image goes over the boundaries of my rounded rectangle drawable.
How can I put the image inside the ImageView
so that everything fits well ?