Android-将图像放入ImageView内而不跨越边界

时间:2020-03-17 14:49:28

标签: android imageview android-glide

我的XML布局中有以下ImageView

<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" />

以下是ImageView的图片:

enter image description here

现在,当用户从相机或图库中选择图像时,我想在该图像视图中显示所选图像的缩略图。这是我的Glide代码来实现的目标:

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)

结果是这样的:

enter image description here

如您所见,图像超出了我的圆角矩形可绘制对象的边界。 如何将图像放入ImageView内,以使所有内容都合适?

0 个答案:

没有答案
相关问题